繁体   English   中英

如何使用户不能连续发布多条消息,discord.js

[英]How do I make it so that a user can not post more than one message in a row, discord.js

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

现在的问题是:我正在寻找创建一个计数频道(类似于Countr Bot ),并且我想这样做,以便如果用户在频道中重复发布,第二条消息将被删除。 我将如何 go 这样做?

我也得到了这个工作。 它抓取最后 2 条消息(因为我要删除的消息计入此列表),并将第二条到最后一条消息的author.id与用户刚刚发送的消息的author.id进行比较。 如果它们相同,则删除最新消息。

message.channel.messages.fetch({ limit: 2 }).then(async messages => {
    lm = messages.last();
    if (lm.author.id == message.author.id) {
        message.delete();
    }
}

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

有两种方法:

  • (文本)静音用户
  • 编辑其在某个频道中发帖的权限

并且 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
   **/
})

暂无
暂无

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

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