Discord.js-即使存在定义,公会ID仍未定义 [英] Discord.js - Guild ID is undefined even though definition is there

查看:90
本文介绍了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.

在我之前详细介绍一下这件事,这是机器人的代码,也许我只是在const中做错了什么: 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.

推荐答案

您在第52行处的代码当前为:

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仍未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆