Discord.js - 公会 ID 未定义,即使有定义

Discord.js - Guild ID is undefined even though definition is there(Discord.js - 公会 ID 未定义,即使有定义)
本文介绍了Discord.js - 公会 ID 未定义,即使有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

制作一个不和谐的机器人.一切正常,除了 -!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 未定义,即使有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Discord.js Arguments With Spaces(Discord.js 带空格的参数)
DiscordJS fetching more then 100 messages(DiscordJS 获取超过 100 条消息)
my discord.js bot doesn#39;t reply to a user message even if there isn#39;t any error(即使没有任何错误,我的 discord.js 机器人也不会回复用户消息)
Make a bot wait for some time before continuing the code(在继续代码之前让机器人等待一段时间)
Invalid Form Body in Discord.js ban command(Discord.js 禁止命令中的无效表单正文)
Set Discord Bot Activity to the number of Online users. Discord.js(将 Discord Bot 活动设置为在线用户数.不和谐.js)