簡體   English   中英

(Node.js) Discord bot 沒有准備好

[英](Node.js) Discord bot won't ready

這是迄今為止我在開發我的 Discord 機器人時遇到的最奇怪的問題。 這個機器人使用 Discord.js。 我使用一個簡單的client.on('ready', () => {}) client.login(<token goes here>)東西,默認的。 但不知何故,控制台沒有給我一個錯誤,也沒有任何日志,但它也沒有做任何事情。 請看一下我的代碼:

const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
//-------------------------------------------
const UserDataModel = require(`./data/userdata`);
const InventoryModel = require(`./data/inventory`);
const { connect } = require(`mongoose`);

client.on('ready', () => {
    console.log('Bot online!');
});

client.on('message', async (message) => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(' ');
    const command = args.shift().toLowerCase();
    //more code down below
}

(async () => {
    await connect(`mongodb://localhost/discord-bot`, {
        useNewUrlParser: true,
        useFindAndModify: false,
        useUnifiedTopology: true
    });
    client.login(token);
});

如您所見,我使用 MongoDB 進行數據存儲。 也許這是一個配置問題,但在花了很多時間四處搜索后,我不知道如何解決這些問題。 非常感謝任何類型的幫助! 如果需要附加代碼,請注釋您需要的部分。

你有一個永遠不會執行的匿名

(async () => {
    await connect(`mongodb://localhost/discord-bot`, {
        useNewUrlParser: true,
        useFindAndModify: false,
        useUnifiedTopology: true
    });
    client.login(token);
})();

應該管用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM