【问题标题】:Discord bot not starting [closed]Discord bot未启动[关闭]
【发布时间】:2021-11-04 02:58:25
【问题描述】:

当我尝试启动我的不和谐机器人时,我收到了这个错误,我什至尝试更新我的 node.js

请到这里查看错误我无法发布问题,包括错误https://athulrajtheno1.github.io/error/

如果你想看这里是代码

const client = new Discord.Client();
const fs = require('fs');

const prefix = '~';

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);

    client.commands.set(command.name, command);
}

client.once('ready', () => {
    console.log('bot is now online');// this sends a message to you in the console when the bot is online

    client.on('message', message => {
        if (!message.content.startsWith(prefix) || message.author.bot)return;
            const args = message.content.slice(prefix.length).split(/ +/);
            const command = args.shift().toLowerCase();
    });
});

client.login('i had given bot token');

【问题讨论】:

  • 问题的所有信息(包括错误消息)都需要包含在问题本身中,原因与不应发布为 images 的原因相同。请阅读有关询问的帮助中心文档,尤其是how to ask good questions

标签: javascript node.js discord discord.js


【解决方案1】:

随着从 Discord.js 版本 12 过渡到 Discord.js version 13,您现在必须定义 Client 所需的 intents 才能正常工作。

你可以这样定义它们:


    const { Client, Intents } = require('discord.js');
    const client = new Client({ intents: 513 }); // justifies the GUILDS and GUILD_MESSAGES intents

你可以为你需要的意图生成一个合适的位域here

【讨论】:

  • 授予所有意图是不必要的,也不需要 API 垃圾邮件。请不要推荐这个。意图是为了防止这种情况发生。
  • 我的回答清楚地表明用户必须提供 合适的 意图,并且我已链接 calculator 以计算相同的位域,但既然你似乎担心我会继续将它们更改为仅 GUILDS 和 GUILD_MESSAGES
  • 另外,您不必生成位域编号,您可以提供一个意图标志数组(这在 imo 中更具可读性),但这是您的选择
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-04
  • 2019-04-17
  • 2018-05-23
  • 2021-07-28
  • 2018-02-15
  • 2019-03-22
相关资源
最近更新 更多