如何使用户不能在一行中发布多个消息,discord.js



我的问题类似于这个问题,但链接的问题是不和谐。py,我正在寻找不和谐的答案,js.

现在的问题:我希望创建一个计数通道(类似于Countr Bot),我想让它,如果一个用户在一个通道中两次发帖,第二条消息被删除。我该怎么做呢?

嗯,禁止用户在某个文本频道发布消息并不难。但真正的问题是,如何管理这个任务并平衡负载。

有两种方法:

  • (text)静音用户
  • 编辑在某个频道发布的权限

并且bot应该具有执行此操作所需的权限。

下面是一个简单的例子:

const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login('your token here').catch(e => console.error(e));
const buffer = new Set();
//listening for all the messages, actually you should listen for messages in a certain channel
bot.on('message', message => {
if (buffer.size) {
//unmute, or return permissions to normal for stored users.
buffer.clear() //clear buffer set
}
buffer.add(message.author.id) //add user with latest message to buffer
/**
* your own code implementation of
* muting or editing message.author.id permission
* in a cerain channel, which should forbid him to post
**/
})

最新更新