[英]I have some errors on an discord.js bot im trying to make:
error: TypeError: Cannot read property 'id' of null at Object.execute (/Users/Desktop/MSBTM/commands/ban.js:18:32) at Client.错误:TypeError:无法在客户端读取 Object.execute (/Users/Desktop/MSBTM/commands/ban.js:18:32) 的 null 属性“id”。 (/Users/Desktop/MSBTM/bot.js:56:36)
(/用户/桌面/MSBTM/bot.js:56:36)
And here is my the code:这是我的代码:
const client = new Discord.Client();
module.exports = {
name: 'ban',
description: "ban peoples ;D",
execute(message, args) {
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);
const reason = args.slice(1).join(" ");
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 :(");
if (user.id === client.user.id) return message.channel.send("You can't ban me, I tried :(");
if (!reason) reason = "No reason provided, please provide an reason to make this active";
member.ban(reason).then(() => {
message.channel.send(`Successfully banned **${user.tag}**`);
}).catch(err => {
message.reply("I was unable to ban the member :(");
})
}
}
can someone help me?有人能帮我吗?
This is because you create a new
client object, which isn't logged in. I suggest you pass the client as a parameter to the function or use the message.client
property.这是因为您创建了一个未登录的
new
客户端对象。我建议您将客户端作为参数传递给函数或使用message.client
属性。 In the following example I used it as a function parameter:在以下示例中,我将其用作函数参数:
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);
const reason = args.slice(1).join(" ");
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 :(");
if (user.id === client.user.id) return message.channel.send("You can't ban me, I tried :(");
if (!reason) reason = "No reason provided, please provide an reason to make this active";
member.ban(reason).then(() => {
message.channel.send(`Successfully banned **${user.tag}**`);
}).catch(err => {
message.reply("I was unable to ban the member :(");
})
}
}
You'd call this function like execute(message, args, client)
then.然后你会像
execute(message, args, client)
一样调用这个函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.