Discord.js ID成员未定义

Discord.js ID成员未定义,discord.js,Discord.js,好吧,我知道我之前在这里,但现在我在尝试添加其他东西时把事情搞砸了。基本上,我在控制台中遇到了一个未定义的错误,因为我不知道如何在Discord.JS的代码中编写它 代码: const id=message.id.members.first() 控制台错误: (node:16412) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'first' of undefined at Object.execut

好吧,我知道我之前在这里,但现在我在尝试添加其他东西时把事情搞砸了。基本上,我在控制台中遇到了一个未定义的错误,因为我不知道如何在Discord.JS的代码中编写它

代码:
const id=message.id.members.first()

控制台错误:

(node:16412) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'first' of undefined
    at Object.execute (C:\Users\Saman\Desktop\gban-bot\commands\test.js:12:39)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:16412) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:16412) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```

message.id.members.first()
不是一件事
message.id
返回雪花,即。已发送消息的id
message.member.id
还返回一个雪花/messaged成员的id。在您的例子中,如果您希望从消息中的提及中获取成员对象本身,那么您正在寻找。这就是
message.indications.members.first()
,它将返回对象本身。使用此选项,您可以访问GuildMember的属性

编辑


嗯,我正在寻找的是一种通过ID禁止的方法,我知道这是一个简单的命令,但出于某种原因,我不知道如何通过ID禁止,更不用说了

为了通过id禁止他们,首先你需要找到行会成员。有3种方法可以找到成员<代码>查找()
获取()
使用的集合。或者您可以直接使用
GuildMemberManager
使用
fetch()
(如果成员不在集合中)。通过这样做,您将获得
GuildMember
对象。你可以通过这样做来禁止他


get()
fetch()
需要雪花。i、 e.ID本身作为字符串。而您需要在
find()
中提供一个函数。如果您还有任何疑问,我将为您链接djs文档。

您似乎有点困惑您想做什么。在一个包含某种形式成员的文档中有两个东西

发送消息的人始终在场。您可以访问它,以及相应的ID,如下所示:

let memberID = message.member.id;
let memberID = message.mentions.members.first().id;
然后是消息中被标记的人。显然,一个并不总是存在,所以您可能需要添加额外的检查。您可以这样访问它:

let memberID = message.member.id;
let memberID = message.mentions.members.first().id;

我正在寻找的是一种通过ID禁止的方法,我知道这是一个简单的命令,但由于某些原因,我无法找到如何通过ID禁止,更不用说了。您需要首先通过ID找到成员对象,因为您只能禁止一个成员。所以:ID->member->ban。看看如何禁止某人。我正在寻找的是一种通过ID禁止的方法,我知道这是一个简单的命令,但出于某种原因,我不知道如何通过ID禁止,一句话也不提。我只是对答案做了一些调整。请查收。