简体   繁体   English

使用 discord.js v12 的速率命令

[英]rate command with discord.js v12

I wanna know how can I make the rate stable so the numbers won't change every time when I tag someone or doing it by myself.我想知道如何使费率稳定,这样每次我标记某人或自己做时数字都不会改变。

client.on('message', message =>{
  if(message.content.toLowerCase().startsWith(prefix + "rate")) {
    let args = message.content.slice(prefix.length).split(/ +/);
    const newEmbed = new Discord.MessageEmbed()
    .setColor('#B99DF0')
    let number = Math.floor(Math.random() * 101);
    if (!args[1]){
    newEmbed.setDescription(`**${message.author.tag} I would rate you a `+number+`/100**`)
    } else {
      let user = message.mentions.users.first();
      if (!user){
        return newEmbed.setDescription('please include who you are rating.')
      }
      newEmbed.setDescription(`**${message.author.tag} I would rate `+user.username+` a `+number+`/100**`)
    }
message.channel.send(newEmbed)
  }
})

Assuming you're talking about having the rating stay constant for specific users, you'll need to use a database of some sort, otherwise you'll have no possible way to do so.假设您正在谈论让特定用户的评级保持不变,您将需要使用某种数据库,否则您将无法这样做。

A good database to start off with would be MongoDB .一个好的数据库是MongoDB If that doesn't work out for you, try out this article on the discord.js tutorial .如果这不适合您,请尝试discord.js 教程上的这篇文章

Take your time to learn the basics of a database, don't rush it for the simplicity of the command.花点时间学习数据库的基础知识,不要为了命令的简单而急于求成。 After you get comfortable with databases, you'll know exactly how to do it熟悉数据库后,您将确切知道如何操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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