Zaczer
Zaczer

Reputation: 1

How can I make my bot set a slowmode on a Discord channel, Discord.js

I'd like to make a command that sets a slow mode on the channel that the command is sent on, I know it involves .setRateLimitPerUser but I'm not sure how to make it work.

Upvotes: 0

Views: 7474

Answers (3)

spifory
spifory

Reputation: 29

Well this is a late message but this is my code for slow mode

const Discord = require('discord.js')

module.exports.run = async (Client, message, args, prefix) => {
    if(!message.content.startsWith(prefix)) return
    const messageArray = message.content.split(' ');
    const args = messageArray.slice(1);
        if(!message.member.hasPermission('MANAGE_MESSAGES')) 
        return message.channel.send("You need `MANAGE_MESSAGES` permission to execute this command.");
  
      message.channel.setRateLimitPerUser(args[0]);
    message.channel.send(`Slowmode has been set to: ${args[0]} Seconds`)
}
  
module.exports.help = {
    name: "slowmode",
    description: "Changes the slowmode of a channel",
    aliases: ['sm']
}

Hope this was helpful :)

Upvotes: 0

Neko
Neko

Reputation: 160

This should work if your bot has the "Manage Channels" permission.

var args = msg.content.substr(1).split(/ +/);
var command = args[0].toLowerCase();

if(command === "slow"){
   if(args[1] != null){
      msg.channel.setRateLimitPerUser(args[1] , "reason");
   }
}

Upvotes: 1

user13429955
user13429955

Reputation:

The first argument is the time in seconds and the second is optional, the

//5 seconds
<TextChannel>.setRateLimitPerUser(5, "reason");

https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=setRateLimitPerUser

Upvotes: 1

Related Questions