简体   繁体   English

如何让我的机器人在 Discord 频道 Discord.js 上设置慢速模式

[英]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.我想制作一个命令,在发送命令的通道上设置慢速模式,我知道它涉及.setRateLimitPerUser但我不确定如何使其工作。

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 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:)希望这有帮助:)

暂无
暂无

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

相关问题 如何让我的 Discord 机器人只忽略某些命令的设置前缀? (不和谐.js) - How can I make my Discord bot ignore the set prefix for certain commands only? (Discord.js) 我可以将 discord 机器人的控制台日志打印到 discord.js 中的特定通道吗? - Can I print the console log of my discord bot into a specific channel in discord.js? 如何在网站上制作 discord.js 机器人统计信息? - How I can make discord.js bot statistics on website? 如何让 discord.js 机器人检测附件 - How can I make discord.js bot detect an attachment 如何使 Discord.js 机器人获取频道上的最后一个附件 - How to make Discord.js bot fetch last attachment on channel 如何发出重置命令来重新启动我的 discord.js 机器人? - How can i make a reset command to restart my discord.js bot? 如何列出我的机器人在控制台中的所有 Discord 服务器 ID? | discord.js - How can I list the all Discord servers ID where my bot are in the console? | discord.js 如何使我的 discord 机器人具有自定义状态 (discord.js) - How do I make my discord bot have a custom status (discord.js) 如何让机器人更改语音频道的名称? (不和谐.js) - How do I make the bot to change a voice channel's name? (Discord.js) Discord.js机器人程序需要帮助-如何使我的机器人每6小时自动执行一项任务而不发送命令? - Discord.js bot help needed - how can I make my bot auto do a task every 6 hours without sending it a command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM