discord.js v12 botclear 命令

时间:2021-02-17 16:06:56

标签: javascript discord discord.js

我有这个 botclear 命令,它应该只清除机器人消息。现在它运行得不太好,它会说 bot cleared messages. 但它不会清除任何内容。同时,它也会发送错误报价。

client.on("message", async message => {
  if (message.content.toLowerCase().startsWith(prefix + "bc")) {
      if (message.author.bot) return;
      if(message.guild === null) return
      if (!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send({embed: {description: 
'You cant use this command since youre missing `manage_messages` perm', color: "RANDOM", timestamp: new Date()}})
      const messages = await message.channel.messages
      .fetch({limit: 100})
      if(!messages) return message.channel.send({embed: {description: 
'There was an error, maybe try again later?', color: "RANDOM", timestamp: new Date()}})
      if (message.channel.type == 'text') {
          message.channel.messages.fetch().then(messages => {
              const FilteredMessages = messages.filter(msg =>  msg.author.bot || 
[message.guild.prefix, message.guild.bcPrefixes,].some((prefix) => msg.content.startsWith(prefix)), true)
              message.channel.bulkDelete(FilteredMessages).catch(err => {
                message.channel.send({embed: {description: 
'There was an error, maybe try again later?', color: "RANDOM", timestamp: new Date()}})
              })
              message.delete()
              message.channel.send({embed: {description: 
`Bot cleared \`${FilteredMessages.size}\` messages :broom:`, color: "RANDOM", 
timestamp: new Date()}}).then(_message => _message.delete({timeout : 2000}))
          }).catch(err => {
              message.channel.send({embed: {description: 'There was an error, maybe try again later?', color: "RANDOM", timestamp: new Date()}});
})}} else {
  if(message.content.toLowerCase() === prefix + "help bc") {
    const newEmbed = new Discord.MessageEmbed()
    .setColor('#00B2B2')
    .setTitle('**Botclean Help**')
    newEmbed.setDescription('This command clears the bot messages.')
    .setFooter(`Requested by ${message.author.tag}`, message.author.displayAvatarURL({format: 'png', dynamic: true}))
    .setTimestamp();
    message.channel.send(newEmbed);
  }
}})

0 个答案:

没有答案