Discord.JS bot 没有响应多个命令

时间:2021-06-14 23:57:04

标签: discord discord.js

我的机器人没有响应除 .purge 命令之外的任何命令。
这是我的代码。

const { Client, MessageEmbed } = require('discord.js');

const client = new Client();
const { prefix, token } = require('./config.json');

client.on('ready', () => {
 client.user.setStatus('invisible');
 console.log('Bot ready!');
client.user.setActivity('Bot is in WIP Do not expect stuff to work', { 

type: 'STREAMING',
url: "https://www.twitch.tv/jonkps4"

});

  console.log('Changed status!');

});

client.on('message', message => {

if (message.content.startsWith(".") || message.author.bot) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();


 
  if (message === 'apply') {
 
message.reply("The Small Developers Application form link is:")
message.reply("https://forms.gle/nb6QwNySjC63wSMUA")

     
     
 

     
   
    
  }




 if (message === 'kick') {

    const user = message.mentions.users.first();
    // If we have a user mentioned
    if (user) {
      // Now we get the member from the user
      const member = message.guild.member(user);
      // If the member is in the guild
      if (member) {
   
        member
          .kick('Optional reason that will display in the audit logs')
          .then(() => {
            // We let the message author know we were able to kick the person
            message.reply(`Successfully kicked ${user.tag}`);
          })
          .catch(err => {
     
            message.reply('I was unable to kick the member \n Maybe due to I having missing permissions or My role is not the higher than the role the person to kick has');
            // Log the error
            console.error(err);
          });
      } else {
        // The mentioned user isn't in this guild
        message.reply("That user isn't in this guild!");
      }
      // Otherwise, if no user was mentioned
    } else {
      message.reply("You didn't mention the user to kick!");
    }
  }


if (command === 'purge') {
        const amount = parseInt(args[0]) + 1;

        if (isNaN(amount)) {
            return message.reply('Not a valid number');
        } else if (amount > 100) {
            return message.reply('Too many messages to clear. \n In order to clear the whole channel or clear more please either ```1. Right click on the channel and click Clone Channel``` or ```2. Execute this command again but more times and a number less than 100.```');
        } else if (amount <= 1) {
                    return message.reply('Amount of messages to clear **MUST** not be less than 1 or more than 100.')
        }
                

        message.channel.bulkDelete(amount, true).catch(err => {
            console.error(err);
            message.channel.send('**There was an error trying to prune messages in this channel!**');
        });
    }







});


client.login(token);

我需要一个特定的命令来工作,它是 .apply 命令 我想知道为什么我的嵌入不起作用。

我试过这个嵌入示例它没有用。

const embed = new MessageEmbed()
      // Set the title of the field
      .setTitle('A slick little embed')
      // Set the color of the embed
      .setColor(0xff0000)
      // Set the main content of the embed
      .setDescription('Hello, this is a slick embed!');
      .setThumbnail('https://tr.rbxcdn.com/23e104f6348dd71d597c3246990b9d84/420/420/Decal/Png')



    // Send the embed to the same channel as the message
    message.channel.send(embed);

我做错了什么?我是 Discord.JS 的新手,需要任何帮助。

1 个答案:

答案 0 :(得分:0)

您使用了 message 参数而不是 command。用 message === 'xxx' 代替 command === 'xxx'。简单的错误,我认为这就是你的意思。当然清除命令有效,因为你把命令 === 'purge' 放在那里