问题
I currently have this as my command:
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);
}
});
I want it so this command can only be ran in a text channel called registration (I have the channel id if needed).
回答1:
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);
}
});
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);
}
});
By the way, you don't have to use message.member
to receive the guild object. You can simply do message.guild
!
来源:https://stackoverflow.com/questions/52045687/check-if-command-is-ran-in-certain-channel