[英]|Discord Bot Error: Cannot find module './commands/ban.js'
[英]Ban module, Discord bot error.. discord.js
1 天前,我针对 discord 机器人发布了一个问题,该机器人说我的 ID 不是 null 的属性。现在它可以工作了。 但它仍然无法禁止,它给了我代码上标记的错误: message.reply("I was unable to ban the member:(");
这是代码:
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 :(");
})
}
}
我检查了机器人是否需要权限,我给了他,但它仍然无法正常工作。
问题在这里
member.ban(() => {
message.channel.send('Successfully banned **${user.tag}**');
}).catch(err => {
message.reply("I was unable to ban the member :(");
})
您正在将整个 function 传递给 ban 方法
真的,你应该调用 function 然后使用 .then .then(() => {})
来处理 promise
它应该看起来像这样
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.