如何解决这个不一致的bot命令问题?

时间:2020-06-10 06:19:00

标签: count command bots discord.js message

问题在于,每当用户键入!count后跟提及的用户时,即使该用户尚未发布新消息,提及的用户的帖子数也会增加1。

编辑:解决了上述问题,但是出现了一个新问题

除了带有!count命令的邮件外,该僵尸程序也无法检测到新邮件

 bot.on("message",async(message)=>{
if(message.content.startsWith('!count')){
    if(message.author.bot) return; // Stop if bot repplies

// Finds an user from the db;
  let messageUser = await Messages.findOne({userID:message.mentions.users.first().id});
  // If the user isn't in the db,create the user
   if(!messageUser){
    messageUser = new Messages({
      userID:message.mentions.users.first().id,
      messages:0
    });
    // Save the user
    await messageUser.save().catch(e=>console.log(e));

  };


let increasePost = async() => {

  let user = await Messages.findOne({userID:message.mentions.users.first().id});
  user.messages++;

await user.save();
let mentioned = message.mentions.users.first();
 message.channel.send(`${mentioned} has   ${ user.messages} messages `)
 // const messages = await Messages.findOne({ userID:message.mentions.users.first().id})
 // console.log(messages.messages);
 //    // message.channel.send(`${message.author.username} has  message ${ messages.messages} messages `)

}

let currentPost = async() => {
  let user = await Messages.findOne({userID:message.mentions.users.first().id});
  user.messages+=0;
await user.save();
// const messages = await Messages.findOne({ userID:message.mentions.users.first().id})
let mentioned = message.mentions.users.first();
 message.channel.send(`${mentioned} has   ${user.messages} messages `)
}

if(message.author!=message.mentions.users.first())
{
currentPost();
}
else
{
increasePost();
}





}
if(message.content.startsWith(`!delete`)){
  const userMessages = await Messages.findOne({ userID:message.mentions.users.first().id});
  userMessages.messages = 0;
  userMessages.save()
  message.channel.send(`${message.mentions.users.first()} has   ${ userMessages.messages} messages `)
}
});

先谢谢了。 这是我的资料库:

https://github.com/Mxk01/Discord-Count-on-progress-

0 个答案:

没有答案