簡體   English   中英

Discord.js v12 禁止命令有效但不禁止成員

[英]Discord.js v12 Ban command which works but not banning the member

我有這個可以工作的禁令命令,但如果我說是來完成操作,它會給我一個錯誤,上面寫着:

Error: DiscordAPIError: Invalid Form Body DICT_TYPE_CONVERT: Only dictionaries may be used in a DictType

我根本不知道該怎么做,因為我對 kick 命令有同樣的禁令命令,而不是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')
});
}})

雖然您可以使用字符串作為.kick()的原因,但.ban()接受object 選項,並且您提供了一個字符串( reason: ${reason} )。 它應該是{reason: reason}或其簡寫形式: { reason }

以下應該有效:

// ...
.ban({ reason })
.then(...)
// ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM