【发布时间】:2018-12-17 11:22:27
【问题描述】:
我正在使用 discord.js 编写音乐不和谐机器人,但我不断收到此错误:
client.on('warn', console.warn);
^
TypeError:无法读取未定义的属性“on”
所以我想知道它是什么。我在下面有机器人代码。如果您愿意,请查看一下,如果您知道如何解决它,我会很高兴。
机器人代码:
const { client } = require('discord.js');
const { TOKEN, PREFIX } = require('./config');
const ytdl = require('ytdl-core');
client.on('warn', console.warn);
client.on('error', console.error);
client.on('ready', console.log('Primary systems online'));
client.on('disconnect', console.log('So you know i disconnected, i will reconnect soon...'));
client.on('reconnecting', console.log('I am reconnecting'));
client.on('message', async msg => {
if (msg.author.bot) return undefined;
if (msg.content.startswith(PREFIX)) return undefined;
const args = msg.content.split(' ');
if (msg.content.startswith('${PREFIX}play')) {
const voiceChannel = msg.member.voiceChannel;
if (!voiceChannel) return msg.channel.send('you need to be in a voice channel to use this function.')
const permissions = voiceChannel.premissionsfor(msg.client.user)
if (!permissions.has('CONNECT')) {
return msg.channel.send('i cant go there give me the permission to go there')
}
if (!permissions.has('SPEAK')){
return msg.channel.send('i cannot speak here! I dont have the rights too')
}
try {
var connection = await voiceChannel.join();
} catch (error) {
console.error('i could not join the voice channel: ${error}');
return msg.channel.send('i could not join the voice channel');
}
const dispatcher = connection.playstream(ytdl(args[1]))
.on('end', () => {
console.log('song ended!')
voiceChannel.leave();
})
.on('error', error => {
console.error(error)
});
dispatcher.setVolumeLogarithmic(5 / 5);
}
});
client.login(TOKEN);
【问题讨论】:
-
但随后出现此错误: const client = new Discord.Client(); ^ ReferenceError: Discord is not defined (ninja edit 得到了那个工作,但现在我不能得到其他工作
-
抛出新的错误。ERR_INVALID_ARG_TYPE('listener', 'Function', listener); ^ 这是我无法工作的事情
标签: javascript discord discord.js