![](/img/trans.png)
[英]How do I make it so my bot remembers what is said to it after I shut it off? I use discord.js for the bot
[英]So i have created a discord poll bot. How do i make it so specific role can use the bot? (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', 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);```
如果我理解正确,您是否希望该命令仅在用户具有特定角色时才起作用?
如果是这样,您可以使用:
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;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.