我有这个禁令命令有效,但如果我说是完成操作,它会给我一个错误说:
Error: DiscordAPIError: Invalid Form Body DICT_TYPE_CONVERT: Only dictionaries may be used in a DictType
我完全不知道在这里做什么,因为我有同样的禁止命令来踢命令,而不是 member.ban
它是 member.kick
并且它工作得很好,没有错误。
client.on('message', async message =>{
if(message.content.toLowerCase().startsWith(prefix + 'ban')) {
if(!message.guild.member(client.user).hasPermission("BAN_MEMBERS")) return message.channel.send('It seems like I dont have the permissions in this server.')
if(!message.member.hasPermission("BAN_MEMBERS")) {
return message.channel.send("You cant use this command since youre missing `ban_members` perm")}
let args = message.content.slice(prefix.length).split(/ +/);
const member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
let reason = args[1]
if(!reason) { reason = 'No provided' }
if(!member) return message.channel.send({embed: {description:
`Please mention the member that you would like to ban`, color: "RANDOM", timestamp: new Date()}})
if(member.user.id === message.author.id) return message.channel.send({embed: {description: `You cant ban yourself`, color: "RANDOM", timestamp: new Date()}})
if(!member.bannable) return message.channel.send({embed: {description: `I cant ban this user`, color: "RANDOM", timestamp: new Date()}})
message.channel.send( { embed: { description: `\`[20s]\` Are you sure you want ban ${member}? \`[yes/no]\``, color: 'YELLOW', timestamp: new Date() } } )
const collector = new MessageCollector(message.channel, msg => msg.author.id === message.author.id, {
time: 20000
})
collector.on('collect', msg => {
switch(msg.content) {
case "yes":
message.delete()
if(member.bannable)
member.ban(`reason: ${reason}`)
.then(() => {
collector.stop('success');
return message.channel.send({embed:{description:
`**${message.author.tag}** I have successfully banned \`${member.user.tag} (${member.user.id})\``, color: "RANDOM", timestamp: new Date()}})
}).catch(err => {
collector.stop('success');
if (err) return message.channel.send({embed: {description: `Error: \`${err}\``, color: "RANDOM", timestamp: new Date()}})
})
break
case "no":
message.delete()
message.channel.send({embed: {description:
`**${message.author.tag}** since you said **no** i will go ahead and cancel this request`, color: "RANDOM", timestamp: new Date()}})
collector.stop('success')
break
default:
message.delete()
message.channel.send({embed: {description:
`**${message.author.tag}** since you said **no** i will go ahead and cancel this request`, color: "RANDOM", timestamp: new Date()}})
collector.stop('success')
}
collector.stop('success')
})
collector.on('end', (ignore, error) => {
if (error && error !== "success") {
return message.channel.send({embed: {description:
`**${message.author.tag}** you ran out of time so i will go and cancel this request`, color: "RANDOM", timestamp: new Date()}})
};
collector.stop('success')
});
}})
答案 0 :(得分:1)
虽然您可以使用字符串作为 .kick()
的原因,但 .ban()
接受 object of options,而您提供的是字符串 (reason: ${reason}
)。它应该是 {reason: reason}
或其简写形式:{ reason }
。
以下应该有效:
// ...
.ban({ reason })
.then(...)
// ...