【发布时间】:2022-01-19 14:38:21
【问题描述】:
我开始编写个人机器人。我收到一个错误
TypeError: Cannot read properties of undefined (reading 'FLAGS')
我假设它无法访问 FLAGS。我不明白为什么,因为我安装了最新的 node 和 discord.js。我在 Discord Developer Portal 上的个人帐户上允许我的 Bot 的“特权网关意图”的所有权限。我遵循了这个教程:https://www.youtube.com/watch?v=Qc9uPgGmQ7I
这是我目前的代码:
require("dotenv").config();
const { Client, Intents } = require("discord.js")
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("interactionCreate", async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === "ping") {
await interaction.reply("Pong!");
}
});
client.login(process.env.SPELL_BOT_TOKEN)
【问题讨论】:
-
你用的是什么版本的 DJS?
-
我更新了我的 DJS 版本,现在它可以工作了。
标签: javascript discord discord.js bots