有人知道密码吗?这是投票机器人代码,所以我还需要在哪里添加代码?如果有人知道,请告诉我代码,这样我就可以理解它以及放在哪里
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("?")
messageReaction.react("?")
message.delete({timeout: 3000, reason: "Poll"});
});
break;
}
});
bot.login(token);```
答案 0 :(得分:0)
如果我理解正确,您希望该命令仅在用户具有特定角色时才起作用?
如果是这样,您可以使用:
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")
}
其中"role"
中的r.name === "role"
是角色的名称。
假设您只希望具有“投票”角色的用户使用该命令,则可以执行以下操作:
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0]){
case "poll":
if(message.member.roles.find(r => r.name === "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("?")
messageReaction.react("?")
message.delete({timeout: 3000, reason: "Poll"});
});
} else {
message.channel.send("You cannot use this command")
}
break;
}
});