![](/img/trans.png)
[英]Discord.js : Add a role on a specific server to a user that DM the bot
[英]Discord bot that counts a specific word per user Discord.js
目前我正在制作一个机器人,它可以计算某个用户说出单词“:p”的次数,无论是在句子中还是单独使用。 发生这种情况时,我希望它为变量添加 +1,以便我可以使用 function 来检查变量中的数字。 使用到目前为止的代码,我可以检测到单词“:p”何时被单独使用,但我无法检测到是谁发送的或何时在句子中。 我尝试使用 author.id,但身份不明。 (代码)
var numberofp = 0;
client.on('message', (message) => {
if(message.content == ':p') {
message.reply('Another one (:');
numberofp = numberofp + 1;
console.log(numberofp);
}
});
当我使用该变量时,它还说:numberofp 未定义。
总的来说,我需要帮助的是:
如果您需要更多代码或信息,请询问:D
我会说使用 quick.db 来计算特定用户的特定单词。
我将为您编写示例代码:
const db = require("quick.db");
client.on('message', (message) => {
if(message.content == ':p') {
let count = db.fetch(`countWord_${message.guild.id}_${message.author.id}`);
db.add(`countWord_${message.guild.id}_${message.author.id}`, count + 1);
}
});
`
and to see how many times specific user used it then use following code:
let count = db.fetch(`countWord_${message.guild.id}_${id of user}`);
message.channel.send(count)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.