-
Автор темы
- #1
const Discord = require(`discord.js`);
const bot = new Discord.Client();
const fs = require(`promise-fs`);
const config = require (`./config.json`);
bot.commands = new Discord.Collection();
loadCommands().then(count => console.log(`Loaded ${count} commands`));
bot.on(`message`, async (message) => {
let arr = message.content.split(/\s+/g);
let args = arr.slice(1);
let name = arr[0].slice(config.prefix.length);
if(!message.content.startsWith(config.prefix)) return;
if(!message.guild) return;
if(message.author.bot) return;
let cmd = bot.commands.get(name);
if(cmd) cmd.run(bot, message, args);
});
bot.on(`guildMemberAdd`, async member => {
bot.logChannel.send(`О Боже кто же это! ${member}!`);
});
bot.on(`guildMemberRemove`, async member => {
bot.logChannel.send(`${member} Покинул нас`);
});
bot.on(`ready`, async () => {
console.log(`Logged as ${bot.user.tag}`);
bot.logChannel = bot.channels.cache.get(`783928263289339926`);
});
bot.login(config.token);
async function loadCommands() {
let dir = await fs.readdir(`command`);
let filles = dir.filter(name => name.endsWith(`.js`));
filles.forEach(fille => {
let name = file.split(`.`)[0];
let cmd = require(`./commands/${name}`);
bot.commands.set(name, cmd);
});
return bot.commands.size;
}
at C:\Users\777\Desktop\discordbot\app.js:43:20
at Array.forEach (<anonymous>)
at loadCommands (C:\Users\777\Desktop\discordbot\app.js:42:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see
(node:3224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
const bot = new Discord.Client();
const fs = require(`promise-fs`);
const config = require (`./config.json`);
bot.commands = new Discord.Collection();
loadCommands().then(count => console.log(`Loaded ${count} commands`));
bot.on(`message`, async (message) => {
let arr = message.content.split(/\s+/g);
let args = arr.slice(1);
let name = arr[0].slice(config.prefix.length);
if(!message.content.startsWith(config.prefix)) return;
if(!message.guild) return;
if(message.author.bot) return;
let cmd = bot.commands.get(name);
if(cmd) cmd.run(bot, message, args);
});
bot.on(`guildMemberAdd`, async member => {
bot.logChannel.send(`О Боже кто же это! ${member}!`);
});
bot.on(`guildMemberRemove`, async member => {
bot.logChannel.send(`${member} Покинул нас`);
});
bot.on(`ready`, async () => {
console.log(`Logged as ${bot.user.tag}`);
bot.logChannel = bot.channels.cache.get(`783928263289339926`);
});
bot.login(config.token);
async function loadCommands() {
let dir = await fs.readdir(`command`);
let filles = dir.filter(name => name.endsWith(`.js`));
filles.forEach(fille => {
let name = file.split(`.`)[0];
let cmd = require(`./commands/${name}`);
bot.commands.set(name, cmd);
});
return bot.commands.size;
}
Ошибка
(node:3224) UnhandledPromiseRejectionWarning: ReferenceError: file is not definedat C:\Users\777\Desktop\discordbot\app.js:43:20
at Array.forEach (<anonymous>)
at loadCommands (C:\Users\777\Desktop\discordbot\app.js:42:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see
Пожалуйста, авторизуйтесь для просмотра ссылки.
). (rejection id: 1)(node:3224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.