简体   繁体   English

Discord 机器人计算每个用户的特定单词 Discord.js

[英]Discord bot that counts a specific word per user Discord.js

Currently I'm making a bot that will count how many times a certain user says the word ':p', whether it's in a sentence or used by itself.目前我正在制作一个机器人,它可以计算某个用户说出单词“:p”的次数,无论是在句子中还是单独使用。 When That happens I would like it to add +1 to a variable so I can use a function to check the number in the variable.发生这种情况时,我希望它为变量添加 +1,以便我可以使用 function 来检查变量中的数字。 With the code I have so far, I can detect when the word ':p' is used by itself but I can't detect who sent it or when its in a sentance.使用到目前为止的代码,我可以检测到单词“:p”何时被单独使用,但我无法检测到是谁发送的或何时在句子中。 I tried using author.id, but that is unidentified.我尝试使用 author.id,但身份不明。 (code) (代码)

var numberofp = 0; 

client.on('message', (message) => {
    if(message.content == ':p') {
        message.reply('Another one (:');
        numberofp = numberofp + 1;
        console.log(numberofp);
    }
});

When I use the variable, it also says: numberofp is undefined.当我使用该变量时,它还说:numberofp 未定义。

Overall what I need help with is:总的来说,我需要帮助的是:

  1. getting the bot to identify when ':p' is used even in the middle of a sentance让机器人识别何时使用 ':p' 甚至在句子中间
  2. Then to get it to check if it is a certain person然后让它检查它是否是某个人
  3. Lastly, to get it to add +1 to the variable numberofp最后,让它为变量 numberofp 添加 +1

If you need any more code or information, just ask:D如果您需要更多代码或信息,请询问:D

I would say use quick.db for counting specific word by specific user.我会说使用 quick.db 来计算特定用户的特定单词。

I'll write sample code for you:我将为您编写示例代码:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM