简体   繁体   English

Discord.js 问题

[英]Discord.js issue

I'm working on a discord bot but some discord.js functions seem undefined.我正在开发一个 discord bot,但一些 discord.js 函数似乎未定义。 For example:例如:

if(!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection){
               play(connection, message);
});

gives me: Cannot read property 'join' of undefined给我: Cannot read property 'join' of undefined

There is a possible reason.有一个可能的原因。

If you are using the latest version of discord.js (v12), then you do message.member.voice.channel rather than message.member.voiceChannel .如果您使用的是最新版本的 discord.js (v12),那么您应该使用message.member.voice.channel而不是message.member.voiceChannel

If you are using the older version of discord.js (v11), then that should be correct and I don't see why it's spitting out an error.如果您使用的是旧版本的 discord.js (v11),那么这应该是正确的,我不明白为什么它会吐出错误。

The current discord.js package version does not work well with the current node version, idk why but I had the same experience so it's best that you stick with your previous versions.当前的 discord.js 包版本不适用于当前的 node 版本,不知道为什么,但我有相同的经历,所以最好坚持使用以前的版本。

Maybe that's the reason..也许这就是原因..

Try to switch to discord.js version 12.0 and nodejs version 13.6 Solved the problem for me.尝试切换到discord.js 12.0版和nodejs 13.6版为我解决了问题。 Tell me if you have any issue.如果您有任何问题,请告诉我。

It is because of the latest Discord version.这是因为最新的 Discord 版本。 Due to this there have been certain changes.为此,发生了一些变化。 Instead of doing message.member.voiceChannel , you should do message.member.voice.channel .而不是做message.member.voiceChannel ,你应该做message.member.voice.channel Hope this fixed your problem.希望这能解决您的问题。

It depends on your version of Discord.js.这取决于您的 Discord.js 版本。 If you're using v12 (Latest version), you need to do message.member.voice.channel Try upgrading your Discord.js or you can just do message.member.voiceChannel You can do either one of those.如果您使用的是 v12(最新版本),则需要执行 message.member.voice.channel 尝试升级您的 Discord.js 或者您可以执行 message.member.voiceChannel 您可以执行其中任何一个。 Note that v12 is more recommended because for v11, they aren't fixing any bugs now.请注意,更推荐使用 v12,因为对于 v11,它们现在没有修复任何错误。 You can also just look at discordjs.guide.您也可以查看 discordjs.guide。

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

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