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 advance
Imgur
4 Replies
d.js toolkit
d.js toolkit8mo 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!
lupus
lupus8mo 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.
Bass
BassOP8mo 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
lupus
lupus8mo ago
You’re welcome
Want results from more Discord servers?
Add your server