Jadi saya mencoba melakukan Fungsi Autorole dengan Discord JS, tetapi masalahnya adalah ada kesalahan besar dan saya tidak tahu mengapa. Itu kode yang saya gunakan:

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)
});

(Saya telah mendefinisikan peran saya di var)

Dan kesalahannya adalah:

[${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)

Dan saya tidak tahu bagaimana cara memperbaikinya

0
Unknown Fllooo 28 Oktober 2019, 16:02

1 menjawab

Jawaban Terbaik

Untuk menghapus peringatan DeprecationWarning: Collection#find: pass a function instead, Anda perlu menggunakan:

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

Dari pada:

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

Untuk TypeError: Supplied parameter was neither a Role nor a Snowflake., saya pikir itu karena perannya tidak ditemukan. Coba tambahkan console.log tepat setelah var.

Kemudian, untuk kesalahan DiscordAPIError: Cannot send an empty message, itu karena Anda tidak dapat mengirim string kosong. Menggunakan:

member.send(Embeds.autorole);

Dari pada:

member.send('', Embeds.autorole);
1
Androz2091 28 Oktober 2019, 13:38