I have this ban command which works but if I will say yes to complete the action it will give me an error that says:
Error: DiscordAPIError: Invalid Form Body DICT_TYPE_CONVERT: Only dictionaries may be used in a DictType
I don't know what to do here at all because I have this same ban command for kick command just instead of member.ban
it's member.kick
and it works great with no errors.
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')
});
}})
While you can use a string as the reason with .kick()
, .ban()
accepts an object of options and you've provided a string instead ( reason: ${reason}
). It should be either {reason: reason}
, or its shorthand form: { reason }
.
The following should work:
// ...
.ban({ reason })
.then(...)
// ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.