我需要帮助,我想在代码中放入一个踢踢和禁止命令,但我不知道该把它放在哪里

时间:2020-08-28 04:48:26

标签: discord discord.js

 client.on("message", (message) => {
if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) {
    if (message.content.startsWith(`${prefix}kick`)) {
      let member = message.mentions.members.first();
      if(!member) return message.channel.send('Cannot find this member');
      member.kick().then((member) => {
        message.channel.send("```" + member.displayName + " has been kicked ```");
      });
    }
  }

这是禁止踢的代码。^^

  1. https://sourceb.in/2e6ba31dc3-这是我不和谐的bot代码,我要在其中输入禁止和踢人命令代码

1 个答案:

答案 0 :(得分:0)

您想在client.on("message", (message)块的内部中放置命令。 我将在您的代码中以它为例:

client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;
 
    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();
 
    if(command === 'ping'){
        client.commands.get('ping').execute(message, args);
    }
    
    // Kick start
    if (command === 'kick') {

      // Only check if the command caller has permission,
      // AFTER the command is called, not before.
      if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) {

        // Define which member needs to get kicked by grabbing the first mentioned guild member
        let member = message.mentions.members.first();

        // If the tagged member is not found in your guild,
        // throw this message
        if(!member) return message.channel.send('Cannot find this member');

        // Proceed to kick the member
        member.kick().then((member) => {
          message.channel.send("```" + member.displayName + " has been kicked ```");
      });
    }

});

我希望这能回答您的问题。如果尚未检查discordjs文档here,请检查它们。他们提供了有关设置机器人的不错的教程。