本文介绍了检查命令是否在某些通道中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前将其作为命令:

bot.on('message', function (message) {
  if (message.content == '!register') {
    message.member.send("Registered!");
    let memberRole = message.member.guild.roles.find("name", "Verified");
    message.member.addRole(memberRole);
  }
});

我想要它,因此此命令只能在称为注册的文本通道中运行(如果需要,我具有通道ID).

I want it so this command can only be ran in a text channel called registration (I have the channel id if needed).

推荐答案

如果只有一个称为 registration 的文本通道,则为以下代码:

Here is the code if you only have one textchannel called registration:

bot.on('message', function (message) {
  if (message.content == '!register' && message.channel.name.toLowerCase() === 'registration') {
    message.member.send("Registered!");
    let memberRole = message.member.guild.roles.find("name", "Verified");
    message.member.addRole(memberRole);
  }
});

如果您有两个称为 registration 的文本通道,我将检查该通道的ID.可以使用以下代码完成此操作:

If you have two textchannels called registration, I would check the ID of the channel. This can be done with this code:

bot.on('message', function (message) {
  if (message.content == '!register' && message.channel.id === 'YOUR CHANNEL ID') {
    message.member.send("Registered!");
    let memberRole = message.member.guild.roles.find("name", "Verified");
    message.member.addRole(memberRole);
  }
});

顺便说一句,您不必使用 message.member 来接收行会对象.您可以简单地执行 message.guild

By the way, you don't have to use message.member to receive the guild object. You can simply do message.guild!

这篇关于检查命令是否在某些通道中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 18:49