简体   繁体   English

discord.js 如何删除所有频道中包含黑名单的消息

[英]discord.js How to delete messages that contain blacklisted word in all channels

I am trying to make command that deletes messages from all channels that contain blacklisted word.我正在尝试发出命令,从包含黑名单单词的所有频道中删除消息。 I don't want command to activate itself but for example when I write.delete in bot commands channel it deletes messages containing banned word from all channels.我不希望命令自行激活,但例如当我在 bot 命令频道中 write.delete 时,它会从所有频道中删除包含禁用词的消息。 With my code command does not delete messages.使用我的代码命令不会删除消息。 Here is my current code for this command:这是此命令的当前代码:

module.exports = {
    name:'delete',
    description: 'deletes all messages containing blacklisted word',
    async execute(message, args){
        const delete = await message.channel.fetch();
        if(message.content.includes('bad-word')){
            message.delete();
        }
    }
}

Any help would be appreciated任何帮助,将不胜感激

Currently, your code is fetching the channel in which you sent the command (and the result is never used), and then it checks if your message, that triggered the command, contains "bad-word".目前,您的代码正在获取您发送命令的通道(并且从未使用过结果),然后它会检查触发命令的消息是否包含“坏词”。 It's not what you want.这不是你想要的。 You should use the TextChannel's messages attribute.您应该使用 TextChannel 的消息属性。 It will give you the channel's MessageManager .它会给你频道的MessageManager You can then use a loop to iterate though the messages and apply your check on each one.然后,您可以使用循环遍历消息并对每条消息进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM