为了账号安全,请及时绑定邮箱和手机立即绑定

Enmap 确保不会自己创建密钥

Enmap 确保不会自己创建密钥

长风秋雁 2021-08-20 18:54:06
如果我自己创建数据库条目,我的代码工作正常,但是当我让其他人尝试创建条目时(即使我使用 .ensure 检查)以前它自动创建了一些条目,但我不确定发生了什么变化,然后它停止创建它们,我试图更改代码,但唯一的解决方案似乎是手动创建条目。错误通常发生在调用+elo命令时const Discord = require('discord.js')const client = new Discord.Client()const Enmap = require("enmap");client.elo = new Enmap({name: "elo"});gameVar = 0;client.on('ready', () => {    console.log("Connected as " + client.user.tag)    // List servers the bot is connected to    console.log("Servers:")    client.guilds.forEach((guild) => {        console.log(" - " + guild.name)    var generalChannel = client.channels.get("602976588543426596") // Replace with known channel ID    generalChannel.send("--10 Man Bot--")      generalChannel.send("To begin a game, type +join")    generalChannel.send("")    })})client.on('message', (receivedMessage) => {    if (receivedMessage.author == client.user) { // Prevent bot from responding to its own messages        return    }    if (receivedMessage.content.startsWith("+")) {        processCommand(receivedMessage)    }    if (receivedMessage.guild) {      client.elo.ensure(`${receivedMessage.guild.id}-${receivedMessage.author.id}`, {        user: receivedMessage.author.id,        guild: receivedMessage.guild.id,        elo: 0,        console.log("entry created")      });    }})function processCommand(receivedMessage) {    let fullCommand = receivedMessage.content.substr(1) // Remove the leading exclamation mark    let splitCommand = fullCommand.split(" ") // Split the message up in to pieces for each space    let primaryCommand = splitCommand[0] // The first word directly after the exclamation is the command    let arguments = splitCommand.slice(1) // All other words are arguments/parameters/options for the command    console.log("Command received: " + primaryCommand)  if (primaryCommand == "elo") {     const key = `${receivedMessage.guild.id}-${receivedMessage.author.id}`;     return receivedMessage.channel.send(`ELO: ${client.elo.get(key, "elo")}`);  }bot_secret_token = client.login(bot_secret_token)
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 189 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信