0
votes

I was wondering if there is a way to block the sending of multiple messages at the same time from different people in a channel discord. Whether his silk with discord.js or discord.py. In itself, I want the bot to take into account the first message sent and ignore others sent at the same time

cordially,

Quentin S.

1
You can use discord slowmode to achieve this. support.discordapp.com/hc/en-us/articles/…. You can configure this directly through discord UI. It also seem that you can configure it through discord.js API, with the TextChannel setRateLimitPerUser method (discord.js.org/#/docs/main/stable/class/…).Gruntzy
@Gruntzy This isn't what he is talking about. Slowmode only limits the messages sent by the same user. i.e. with a slowmode setting of 5 seconds, if I send a message, I must wait 5 seconds before sending again, but another user can send a message within those 5 seconds and then have to wait his OWN 5 seconds.Timesis
@Timesis Exactly, what I would like to do is that my bot takes into account the first message sent and not the others received at the same time by different users.Quentin
You can't block users sending messages like that. You can however have the bot ignore or delete the other messages sent after receiving the first one. Not exactly sure what your use case is though. Either way, a message has to actually post in the channel in order for a bot to act on it. There's no way to preempt the actual sending/posting of the message.Anu6is

1 Answers

0
votes

One solution would be to track the timestamp of the last message listened to, and then ignore any messages sent before a set amount of time has elapsed. See this example...

let lastMessageTime;
const sec = 2; // Seconds to wait between messages.

client.on('message', message => {
  if (!message.guild || message.author.bot) return;

  if (lastMessageTime && message.createdTimestamp - (sec * 1000) < lastMessageTime) return;
  else lastMessageTime = message.createdTimestamp;

  // Continue with 'message' event.
});