[英]How do I define discord. "error discord is not defined"
const { Client, Intents, DiscordAPIError } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const ytdl = require("ytdl-core")
const fs = require('fs');
client.commands = new Discord.Collection(); //error here
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);
}
const PREFIX = '$';
var version = '1.0.1'
var servers = {};
client.once('ready', () => {
console.log ('Smegma Music 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();
if(command === 'ping'){
message.channel.send('Shutup Bitch!');{
}
function play(connection, message){
var server = servers [message.guild.id];
server.dispatcher = connection.playStream(ytdl(server.queue[0], {filter: "audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0]){
play(connection, message);
}else {
connection.disconnect();
}
});
client.login('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); //at end
}
}});
Line 9 is where the problem is.第 9 行是问题所在。 "client.commands = new Discord.Collection();" “client.commands = new Discord.Collection();” I get an error when I try to run 'node.'当我尝试运行“节点”时出现错误。 saying说
ReferenceError: Discord is not defined at Object. (C:\MusicBot\main.js:9:23) ReferenceError:Discord 未在 Object 处定义。(C:\MusicBot\main.js:9:23)
It was working yesterday, however this was with a different approach to commands.昨天它还在工作,但是这是使用不同的命令方法。 I am trying to create a basic command handler here.我试图在这里创建一个基本的命令处理程序。
Above trying to make a new collection, you can define discord like this:上面尝试创建一个新集合,你可以这样定义 discord:
const Discord = require("discord.js")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.