简体   繁体   English

禁止模块,Discord 机器人错误.. discord.js

[英]Ban module, Discord bot error.. discord.js

1 day ago i publish an issue with for a discord bot that said that my id was not a property of null. Now its works. 1 天前,我针对 discord 机器人发布了一个问题,该机器人说我的 ID 不是 null 的属性。现在它可以工作了。 But it still not able to ban, and it gives me the error marked on the code: message.reply("I was unable to ban the member:(");但它仍然无法禁止,它给了我代码上标记的错误: message.reply("I was unable to ban the member:(");


This is the code:这是代码:

const Discord = require('discord.js');
const client = new Discord.Client();



module.exports = {
   name: 'ban',
   description: "ban peoples ;D",
   execute(message, args, client) {
       if (!message.member.hasPermission("BAN_MEMBERS") ||
           !message.member.hasPermission("ADMINISTRATOR")) return message.channel.send("You don't have a permissions to do this, maybe later ;) ");

       const user = message.mentions.users.first();
       const member = message.guild.member(user);
       

       if (!user) return message.channel.send("Please mention the user to make this action");

       if (user.id === message.author.id) return message.channel.send("You can't ban yourself, I tried :(");


       member.ban(() => {
           message.channel.send('Successfully banned **${user.tag}**');
       }).catch(err => {
           message.reply("I was unable to ban the member :(");
       })
   }
}

i checked to see if the bot needs permissions, i gave it him but it still not working.我检查了机器人是否需要权限,我给了他,但它仍然无法正常工作。

The issue is here问题在这里

member.ban(() => {
    message.channel.send('Successfully banned **${user.tag}**');
}).catch(err => {
    message.reply("I was unable to ban the member :(");
})

You are passing an entire function into the ban method您正在将整个 function 传递给 ban 方法

Really you should be calling the function then using .then(() => {}) to handle the promise真的,你应该调用 function 然后使用 .then .then(() => {})来处理 promise

It should look like this它应该看起来像这样

member.ban()
    .then(() => {
        message.channel.send('Successfully banned **${user.tag}**');
    })
    .catch((err) => {
        message.reply("I was unable to ban the member :(");
        console.error(err);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM