[英]How do I prevent this from happening from my AFK Command (discord.js)
I have an AFK
command but the problem is when do !afk
in my server and I type something else on a different server, it says "Welcome back ur not afk anymore" even though I did !afk
in my server.我有一个AFK
命令,但问题是何时在我的服务器中执行!afk
并且我在另一台服务器上键入其他内容时,即使我在我的服务器中执行了!afk
,它也会显示“欢迎回来你不再 afk” 。 I am not sure how to fix this我不知道如何解决这个问题
The Code:编码:
bot.afk = new Map();
bot.on("message", message => {
if (db.has(message.author.id + '.afk')) {
message.channel.send("welcome back!")
db.delete(message.author.id + '.afk')
db.delete(message.author.id + '.message')
}
})
bot.on('message', message => {
if (message.author.bot) return
message.mentions.users.forEach(user => {
if (db.has(user.id + '.afk')) message.channel.send(`That user is AFK!`)
})
})
bot.on('message', message => {
if (!message.content.startsWith(PREFIX)) return;
let args = message.content.substring(PREFIX.length).split(' ');
switch (args[0]) {
case 'afk':
db.set(message.author.id + '.afk', 'true')
db.set(message.author.id + '.messageafk', message.content.split(' ').slice(1))
message.channel.send(`U are now afk`)
break;
};
});
You could store the channel id in your db for the user so:您可以为用户将频道 ID 存储在您的数据库中,以便:
let isafk = db.fetch(`isafk_${message.channel.id}_${message.author.id}`) //however you fetch your db values
if(isafk) {
//code for if is afk in that channel
} else {
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.