Enmap 确保不会自己创建密钥

如果我自己创建数据库条目,我的代码工作正常,但是当我让其他人尝试创建条目时(即使我使用 .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)


长风秋雁
浏览 190回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript