【发布时间】:2020-07-21 23:50:08
【问题描述】:
我使用的是 discord.js 版本“12.1.1”,对于这个脚本“banuser.js”,我使用的是命令处理程序。
现在我只想禁止此人,但我不断收到此错误: (node:30800) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'banable' of undefined
如果这可行的话,很酷的功能将是 unban + 定时禁止 -> 当我禁止某人时,我可以说 1/7 day ben 或 in hours ... 但现在我想让它发挥作用,这样我就可以禁止人们。
const discord = require("discord.js");
module.exports.run = async (bot, message, args) => {
if (message.member.hasPermission("BAN_MEMBERS")) {
if (!message.mentions.users) return message.reply('You must tag 1 user.');
else {
const channel = message.guild.channels.cache.get("696692048543088691");
const member = message.mentions.members.first();
let reason = message.content.split(" ").slice(2).join(' ');
if (member.banable== false) return message.channel.send("That user cannot be baned!");
else {
if (!reason) reason = (`No reason provided.`);
await member.send(`You have been baned from **${message.guild.name}** with the reason: **${reason}**`)
.catch(err => message.channel.send(`⚠ Unable to contact **${member}**.`));
await member.ban(reason);
const banEmbed = new discord.MessageEmbed()
// .setAuthor(member.user.tag, member.user.iconURL()) -> kleine avatar
.setAuthor(member.user.avatarURL())
.setThumbnail(member.user.avatarURL())
.setAuthor(member.user.tag)
.setColor("#ee0000")
.setTimestamp()
.addField("Kicked By", message.author.tag)
.addField("Reason", reason);
// console.log(member.user.avatarURL('Heeft geen avatar'))
await channel.send(banEmbed);
console.log(`${message.author.tag} Baned ${member.user.tag} from '${message.guild.name}' with the reason: '${reason}'.`);
}
}
} else {
message.channel.send("You do not have permission to use the ban command.");
return;
}
}
module.exports.help = {
name: "banuser"
}
/* module.exports.run = async (bot, 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.");
let user = message.mentions.users.first();
let member = message.guild.member(user);
let reason = args.slice(22).join(" ");
if (!user) return message.channel.send("Please mention the user.");
if (user.id === message.author.id) return message.channel.send("You can't ban yourself.");
if (user.id === client.user.id) return message.channel.send("You can't ban me.");
if (!reason) reason = "No reason provided";
member.ban(reason).then(() => {
message.channel.send(`Successfully banned **${user.tag}**`);
}).catch(err => {
message.reply("I was unable to ban the member.");
})
}
module.exports.help = {
name: "banuser"
} */
这是我目前的代码
【问题讨论】:
-
您应该使用
message.mentions.users.first()而不是message.mentions.members.first()吗?
标签: javascript discord discord.js