gpt4 book ai didi

javascript - 我正在尝试为我的私有(private) Discord JS 机器人执行 Autorole 功能

转载 作者:行者123 更新时间:2023-12-02 22:40:53 25 4
gpt4 key购买 nike

所以我试图用 Discord JS 做一个 Autorole 函数,但问题是我出现了一个大错误,我不知道为什么。这是我使用的代码:

client.on('guildMemberAdd', member => {
console.log(`[${b}:${c}` + member.user.tag + 'ist dem Server beigetreten!');

var role = member.guild.roles.find('name', 'user');
member.addRole(role);
member.send('', Embeds.autorole)
});

(我已经在 var 中定义了我的 Angular 色)

错误是:

[${b}:${c}]DoomCity#3747ist dem Server beigetreten!
(node:20220) DeprecationWarning: Collection#find: pass a function instead
(node:20220) UnhandledPromiseRejectionWarning: TypeError: Supplied parameter was neither a Role nor a Snowflake.
at GuildMember.addRole (D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\discord.js\src\structures\GuildMember.js:454:38)
at Client.<anonymous> (D:\FVKR\Desktop\Team Unknown\Discord Bot\index.js:198:12)
at Client.emit (events.js:209:13)
at Guild._addMember (D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\discord.js\src\structures\Guild.js:1298:19)
at GuildMemberAddHandler.handle (D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\discord.js\src\client\websocket\packets\handlers\GuildMemberAdd.js:12:13)
at WebSocketPacketManager.handle (D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:209:13)
(node:20220) 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(). (rejection id: 1)
(node:20220) [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.
(node:20220) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
at D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
at D:\FVKR\Desktop\Team Unknown\Discord Bot\node_modules\snekfetch\src\index.js:215:21
at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:20220) 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(). (rejection id: 3)

我不知道如何解决

最佳答案

要删除 DeprecationWarning: Collection#find: pass a function instead 警告,您需要使用:

var role = member.guild.roles.find((role) => role.name === "user");

而不是:

var role = member.guild.roles.find("name", "user");

对于类型错误:提供的参数既不是 Angular 色也不是雪花。,我认为这是因为找不到 Angular 色。尝试在 var 之后添加 console.log

然后,对于 DiscordAPIError: Cannot send anempty message 错误,这是因为您无法发送空字符串。使用:

member.send(Embeds.autorole);

而不是:

member.send('', Embeds.autorole);

关于javascript - 我正在尝试为我的私有(private) Discord JS 机器人执行 Autorole 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58591445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com