Confirmation and error messages problem:
Hi everybody
I'm currently trying to make a slash command with 4 subcommands:
The first creates a new role and adds users within it
The second allow to add people in roles
The third removes people from roles
The fourth and last delete the selected role
The command does what I expect. It aims to allow people to create custom roles and add many users so they can @ that role when they want instead of mention all the members of that group each time they have to speak to them. With the bot, I don't have to manage this myself, and member can do it by themselves.
The problems comes when I want to put an error message: if a user try to manage admin role for exemple, Discord API doesn't allow it (which is exactly what I want, no problem with that) but in my chat I have a confirmation message like if the command worked, but it actually not. Beyond the problem if this command, it will be a big problem if I'm not able to create simple confirmation message when the command works and an error message if it's not.
So here is my code for one of the subcommands, but the problem is the same for the 3 others (case is in french, I translated console.error + interactions). I don't post it directly because discord doesn't display it properly but if you want the whole code just tell me I'll do a pastebin :
https://i.imgur.com/s1i9Acz.png
When I use
interaction.reply
line 100 I get
DiscordAPIError[40060]: Interaction has already been acknowledged
pointing at node_modules\@discordjs\rest\dist\index.js:722:13
And if I use interaction.followUp
:
Error [InteractionNotReplied]: The reply to this interaction has not been sent or deferred.
I also tried to put a try...catch but it's exactly the same way
Actually, I could do this role attribution myself, but I'm not done with slash commands creation and if I don't understand how manage confirmation and error messages I'll get in trouble anyway.
If I delete the confirmation embed to see what it does, it prints the confirmation embed of the next subcommand so I'm sure I did something wrong (for not to say I totally messed up, I'm not a developper but I try to learn) with the embed place and the if/else, but after many researchs I don't manage to understand how to correct this, so I turn to you.
Thx by advanceDT
d.js toolkit•16d ago
- 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!L
lupus•16d ago
So I can see that you want to send a message with the added users in the end.
.forEach
does not support async functions. You could try looping through users with a for...of loop and then add the users that way. However, you'll have to add an await to member.roles.add as well as probably deferring the reply beforehand. You could then create a new array with failed users and display them in the confirmation message as well.B
Bass•16d ago
Thanks a lot for your answer, in my test I didn't even considered that one user could have the problem and an other not, making my method impossible. I'll try what you told thx again
L
lupus•16d ago
You’re welcome
Support server for discord.js, a Node.js module to interact with the Discord bot API.
58KMembers
View on DiscordWant results from more Discord servers?
More Postsset undefinedthis.client.voice.adapters.set(this.id, methods);
^
TypeError: CannCan not read dmsI for somereason can not fetch dms sent to my discord bot using 'messageCreate',
I have Direct messwhere would one find the d.js "send a message in a channel" chain in the v14 docssorry if i got the terminology wrong im not super used to JS but where could i find the chain for seERREUR```[ERROR] DiscordAPIError[50035]: Invalid Form Body
embeds[0][LIST_ITEM_VALUE_REQUIRED]: List item Is there a way to loop through each guild and channel without getting error using fetch?Basically, right now I am using try/catch without logging the error(s), because it works. But, if I Bot cannot play musicI recently started a bot that play music, everything works just fine, no error, the bot is able to fThis interaction failed but components are workingI'm trying to create an interactive settings command by using interactable dropdown menus and buttoninteraction.channel is null in DMit works for servers, but not in direct message as 'user app'.
I already use as suggestions of otheDiscord cdn not working?I'm storing a link of an image attachment `...cdn.discordapp.com/attachments...` and the content is this isn’t really an error but more of a questionHow would you exactly use the presence to detect if a specific role has online members? as i am try