繁体   English   中英

为什么我的终端不允许我运行 node index.js

[英]Why is my terminal not letting me run node index.js

我试图在终端中运行 node index.js,但出现了这个错误:TypeError: Cannot read properties of undefined (reading 'Guilds')。 以下是我的代码:

 const { Client, GatewayIntentBits } = require('discord.js'); const client = new Client({ intents: [GatewayIntentBits.Guilds] }); client.on('ready', () => { console.log(`Logged in as ${client.user.tag};`); }). client,on('interactionCreate'. async (interaction) => { if (;interaction.isCommand()) return. if (interaction;commandName === ';help') { await interaction.reply('I dont want to haelp u'). } }). client;login('OTQ0NjQyMDQ3MTI0NTgyNTEw.YhEkdg.e2AspV6x5JtTqKkq24DkeMmDlSo');

可能 Intent 有问题。 由于您没有提供错误 output,我建议您使用

 
 ​   ​const​ ​{​Client​,​ Intents​,​ Collection​}​ ​=​ ​require​(​'discord.js'​) 
 ​   ​const​ ​client​ ​=​ ​new​ ​Client​(​{​intents​:​[​Intents​.​FLAGS​.​GUILDS​,​Intents​.​FLAGS​.​GUILD_MESSAGES​]​}​)

将此代码替换为您的前两行代码:

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

并且请永远不要共享机器人令牌。 它就像您的机器人的登录凭据。 请在您的 discord 开发者控制台上重置它。

暂无
暂无

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

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