首页 > 解决方案 > 在 2 条用户消息之前删除机器人消息

问题描述

就我所知,javascript 仍然含糊不清,我无法准确说明我制作的以下代码的敏感性。我正在编写一个不和谐的机器人,它将消息分类为各种渠道,这个问题让我想到了如何通过在机器人消息之后发送 2 条用户消息后删除后续机器人消息来对机器人进行编程。

if (bot.on(client, user.msg = '2'));{
    msg.channel('message' = msg.delete)
}

需要帮助,我希望我的查询在我所暗示的上下文中是有意义的,问候,编码器

PS:如何更改机器人消息文本颜色?

标签: discord.js

解决方案


无意冒犯,但您的代码完全错误,所以我只是编写了一些新代码。

bot.on('message', aysnc message => {
   var messagenumber = 0; //Makes variable for the number of messages sent

   if(message.member.user.username === bot.user.username) return; //If the person who posts a message is the bot, it doesn't the code below.
   if(messagenumber = 1) return bulkDelete(100), messagenumber = 0 //Checks if the variable is 1, and if it is, this means it's the second time a message posted, so it deletes messages (Limit is 100) then resets variable. 
   messagenumber = 1; //Makes variable 1 (This is to make it know it is the the second time a message is posted for the next time).
});

我没有测试此代码,因此它可能无法正常工作,但如果它确实有效,我希望它对您的机器人有所帮助。

对于 PS(更改文本颜色):您可以使用这些(将“NoKeyWordsHere”替换为您的消息)。我不建议这样做,因为将其添加到发送的每条消息中都需要很长时间。(你也可以在你的消息中使用这些)


推荐阅读