【发布时间】:2021-11-20 17:25:53
【问题描述】:
我是 discord.js 的新手,并且一直在关注一个使用过时版本的 discord.js 的 youtube 教程(链接在这里:https://www.youtube.com/watch?v=22BFybCwSFU&list=PL-Ux9UcyEUaNxn_TbByomT-01UUKHOoD1&index=3&ab_channel=Exane)(这给我带来了一些问题)
他们的代码:
const Discord = require('discord.js')
const bot = new Discord.Client();
const fs = require("fs")
bot.commands = new Discord.Collection();
在最后一行(第 5 行),当我尝试输入 new Discord.Collection();我收到 ReferenceError:Discord 未定义,但当我删除“Discord”时。从这条线上,我得到了 ReferenceError: Collection is not defined。
我根据 cmets 更改了我的代码,人们在使用更新版本的 discord.js 和 node.js 时也遇到了困难,但到目前为止还没有找到解决办法。我的代码将放在下面,如果这是一个愚蠢/明显的修复,我真的很抱歉,非常感谢您的阅读!
const { Client, Intents, DiscordAPIError, CommandInteractionOptionResolver } = require("discord.js");
const bot = new Client({ intents: ["DIRECT_MESSAGES", "GUILD_MESSAGES"] });
const fs = require("fs")
bot.Commands = new Collection();
(我认为我应该使用名称“Discord”定义第一个“const”变量,但是当我尝试这样做时,我遇到了同样的错误)
编辑:在此之前我忘了提到我必须在第一行添加(窃取)代码以允许我在创建新客户端时添加意图,因为在旧版本中您以前不需要添加意图在这里,但是在 discord.js 13.3 版中,如果没有它,我的代码将无法运行
【问题讨论】:
标签: discord discord.js constants client