Add role to user
Hey guys, im trying to add role to user but it didn't work
But it return
D:\Project\Discord\Bots\GoodLuck\GoodLuck\command\BlackJack.js:121
const member = guild.members.find((m) => m.id === interaction.user.id);
^
TypeError: guild.members.find is not a function
at BlackJack.interactionCreate (D:\Project\Discord\Bots\GoodLuck\GoodLuck\command\BlackJack.js:121:36)
at Object.execute (D:\Project\Discord\Bots\GoodLuck\GoodLuck\Events\interactionCreate.js:14:22)
at Client.execute (D:\Project\Discord\Bots\GoodLuck\GoodLuck\Handler\eventHandler.js:13:44)
at Client.emit (node:events:523:35)
at InteractionCreateAction.handle (D:\Project\Discord\Bots\GoodLuck\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (D:\Project\Discord\Bots\GoodLuck\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (D:\Project\Discord\Bots\GoodLuck\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (D:\Project\Discord\Bots\GoodLuck\node_modules\discord.js\src\client\websocket\WebSocketShard.js:494:22)
at WebSocketShard.onMessage (D:\Project\Discord\Bots\GoodLuck\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10)
at callListener (D:\Project\Discord\Bots\GoodLuck\node_modules\ws\lib\event-target.js:290:14)
Node.js v20.3.1
How can I add role to user?26 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Thank your response,
<GuildMember>.roles.add(…)
this add parameter is role's id ?Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
It works perfectly just local parameter, but when I use it on express server it return this
DiscordAPIError[50035]: Invalid Form Body
user_id[NUMBER_TYPE_COERCE]: Value "favicon.ico" is not snowflake.
at handleErrors (D:\Project\Starly\web\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (D:\Project\Starly\web\node_modules\@discordjs\rest\dist\index.js:1072:23)
at async SequentialHandler.queueRequest (D:\Project\Starly\web\node_modules\@discordjs\rest\dist\index.js:913:14)
at async _REST.request (D:\Project\Starly\web\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async GuildMemberManager._fetchSingle (D:\Project\Starly\web\node_modules\discord.js\src\managers\GuildMemberManager.js:221:18) {
requestBody: { files: undefined, json: undefined },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: {
user_id: {
_errors: [
{
code: 'NUMBER_TYPE_COERCE',
message: 'Value "favicon.ico" is not snowflake.'
}
]
}
}
},
code: 50035,
status: 400,
method: 'GET',
url: 'https://discord.com/api/v10/guilds/1141562591940968481/members/favicon.ico'
}
Node.js v20.3.1
[nodemon] app crashed - waiting for file changes before starting...
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
oh
req.params.id
is this a favicon.ico
?Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
I just edit it to this
but it still return error ..
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
I think this value
const id = req.params.id
is problemUnknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Yeah It just return below pic
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Yeah!
that is a user Id
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
I was a idiot ....
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
WHen I was tried to print
it return
lmao
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Next Step: Getting params Without favicon.ico
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Ohhhh I wonder why the params value returning soo stealthy The "favicon.ico"
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Thank uu then it won't return favicon anymore?
Thank u ill try it later
Thank uuuuu it work perfectly !!