Я работаю над своим первым диссонансом. js бот. Мне нужно руководство - PullRequest
0 голосов
/ 16 апреля 2020

Когда я запускаю бота, он говорит: «Бот запущен с неопределенными пользователями в неопределенных каналах неопределенных гильдий». Затем, когда я go использую команду в разногласиях, он говорит: «(узел: 9928) UnhandledPromiseRejectionWarning: ReferenceError: команда не определена». Вот мой код:

bot.on("ready", () => {
  bot.on("message", (message) => {
    bot.on("message", async message => {
      if(message.content.indexOf(config.prefix) !== 0) return;
      let prefix = config.prefix;
// It's good practice to ignore other bots. This also makes your bot ignore itself
  // and not get into a spam loop (we call that "botception").
  if(message.author.bot) return;
  //Discord Server Ping
  if(command === "ping") {const m = await message.channel.send("Ping?");
  m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(bot.ping)}ms`);
}

//Kick command
if(command === "kick") { if(!message.member.roles.some(r=>["Admin", "Mod, Owner, Co-Owner"].includes(r.BravoSierra2336)) )
return message.reply("Sorry, you don't have permissions to use this!");
let member = message.mentions.members.first() || message.guild.members.get(args[0]);
if(!member)
  return message.reply("Please mention a valid member of this server");
if(!member.kickable) 
  return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
   member.kick(reason)
  .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`));
message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${reason}`);
}
//Ban command
if(command === "ban") { if(!message.member.roles.some(r=>["Owner, Co-Owner"].includes(r.name)) )
return message.reply("Sorry, you don't have permissions to use this!");
let member = message.mentions.members.first();
    if(!member)
      return message.reply("Please mention a valid member of this server");
    if(!member.bannable) 
      return message.reply("I cannot ban this user! Do they have a higher role? Do I have ban permissions?");
    let reason = args.slice(1).join(' ');
    if(!reason) reason = "No reason provided";
    await member.ban(reason)
      .catch(error => message.reply(`Sorry ${message.author} I couldn't ban because of : ${error}`));
    message.reply(`${member.user.tag} has been banned by ${message.author.tag} because: ${reason}`);
  }

});





  // This event will run if the bot starts, and logs in, successfully.
  console.log(`Bot has started, with ${bot.users.size} users, in ${bot.channels.size} channels of ${bot.guilds.size} guilds.`); 
  // Example of changing the bot's playing game to something useful. `client.user` is what the  
  // docs refer to as the "ClientUser".
  bot.user.setActivity(`Serving ${bot.guilds.size} servers`);
});

bot.on("guildCreate", guild => {
  // This event triggers when the bot joins a guild.
  console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
  bot.user.setActivity(`Serving ${bot.guilds.size} servers`);
});

bot.on("guildDelete", guild => {
  // this event triggers when the bot is removed from a guild.
  console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
  bot.user.setActivity(`Serving ${bot.guilds.size} servers`);
})});
...