Javascript 所以我创建了一个discord投票机器人。如何使特定角色可以使用bot?(discord.js)
有人知道密码吗?这是投票机器人的代码,那么我需要在哪里添加代码呢?如果有人知道,请告诉我代码,以便我能理解它,并把它放在哪里Javascript 所以我创建了一个discord投票机器人。如何使特定角色可以使用bot?(discord.js),javascript,discord.js,Javascript,Discord.js,有人知道密码吗?这是投票机器人的代码,那么我需要在哪里添加代码呢?如果有人知道,请告诉我代码,以便我能理解它,并把它放在哪里 const bot = new Discord.Client(); const token = "bot token here"; const PREFIX = "T!"; bot.on('ready', () =>{ console.log("who has woken the almighty one"); }); bot.on('message
const bot = new Discord.Client();
const token = "bot token here";
const PREFIX = "T!";
bot.on('ready', () =>{
console.log("who has woken the almighty one");
});
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0]){
case "poll":
const Embed = new Discord.MessageEmbed()
.setColor(0xFFC300)
.setTitle("Start a poll")
.setDescription("T!poll to start a poll");
if(!args[1]){
message.channel.send(Embed);
}
let msgArgs = args.slice(1).join(" ");
message.channel.send(msgArgs).then(messageReaction => {
messageReaction.react("If i understand correctly, you want the command to only work if the user has a specific role?
If so you can use:
if(message.member.roles.find(r => r.name === "role")){
message.channel.send("You can use this command!")
} else {
message.channel.send("You cannot use this command")
}
const bot=newdiscord.Client();
const token=“此处的bot token”;
const PREFIX=“T!”;
bot.on('ready',()=>{
日志(“谁唤醒了全能者”);
});
bot.on('message',message=>{
设args=message.content.substring(PREFIX.length).split(“”);
开关(参数[0]){
“投票”一案:
const Embed=new Discord.MessageEmbed()
.setColor(0xFFC300)
.setTitle(“开始投票”)
.setDescription(“T!轮询以开始轮询”);
如果(!args[1]){
message.channel.send(嵌入);
}
让msgArgs=args.slice(1).join(“”);
message.channel.send(msgArgs).then(messageReaction=>{
messageReaction.react(“如果我理解正确,您希望该命令仅在用户具有特定角色时才起作用
如果是,您可以使用:
其中中的“role”
是角色的名称
假设您只希望具有“poll”角色的用户使用该命令,您可以执行以下操作:
bot.on('message',message=>{
设args=message.content.substring(PREFIX.length).split(“”);
开关(参数[0]){
“投票”一案:
if(message.member.roles.find(r=>r.name==“poll”)){
const Embed=new Discord.MessageEmbed()
.setColor(0xFFC300)
.setTitle(“开始投票”)
.setDescription(“T!轮询以开始轮询”);
如果(!args[1]){
message.channel.send(嵌入);
}
让msgArgs=args.slice(1).join(“”);
message.channel.send(msgArgs).then(messageReaction=>{
messageReaction.react(“