問題描述
制作一個不和諧的機器人.一切正常,除了 -!prefix
的一個命令.-!
是前綴,命令采用 args 并更改服務器的前綴.
Making a discord bot. Everything works fine, except the one command of -!prefix
. -!
being the prefix, and the command taking the args and changing the prefix of the server.
在詳細介紹這件事之前,這是機器人的代碼,也許我只是在 consts 中做錯了什么:Hastebin 鏈接
Before I go into detail about this while thing, here's the bot's code, maybe I simply did something wrong in the consts: Hastebin Link
這里的錯誤在第 52 行,根據控制臺:控制臺日志
The error here is in line 52, according to the console: Console Log
我對如何處理未定義"感到困惑.我嘗試使用 message.guild.id
屬性作為變量,以及代碼中顯示的變量.我試過把它移到多個地方,雖然它唯一注冊的地方是前綴命令的內部(由于這個錯誤,它目前被破壞了.)
I'm confused as to what to do with this being "undefined." I've tried using the message.guild.id
property as the variable, and also the one shown on the code. I've tried moving it to multiple places, although the only place it even registers is INSIDE of the prefix command (which is currently broken because of this error.)
任何人有任何修復?我不是整個 JavaScript 方面的專家,因為我是從 Python 和普通 Java 過來的.
Anyone have any fixes? I'm not that much of an expert in the whole JavaScript thing, as I came over from Python and regular Java.
推薦答案
您在 line 52
的代碼目前是:
Your code at line 52
is currently:
var server = bot.guilds.get(message.author).id
您當前正在將 User
對象傳遞到 .get()
中,該對象應該會收到 id 或雪花
.
You're currently passing a User
object into the .get()
which should recieve an id or snowflake
.
考慮到這一點,您的代碼應如下所示:
With this in mind, your code should look like:
var server = bot.guilds.get(message.guild.id).id;
但是,這有點過分,因為您可以簡單地將其縮短為:
However, this is a bit excessive because you can simply shorten it to:
var server = message.guild.id;
現在你說你已經
嘗試使用 message.guild.id
屬性作為變量,也是代碼中顯示的變量.
tried using the
message.guild.id
property as the variable, and also the one shown on the code.
我不確定你的意思是不是我剛才的建議,但如果是,請通知我.
I'm not sure if you mean what I just suggested, but if so please notify me.
這篇關于Discord.js - 公會 ID 未定義,即使有定義的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!