简体   繁体   中英

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.

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

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");
   }
}

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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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