#huh both awaiting and using catch isn t
1 messages ยท Page 1 of 1 (latest)
d
at the bottom of the page, you get the simple example
that's the difference between awaiting and not awaiting, when it comes to catch an error.
so you got two options:
one is to do like upper, using .catch() all of the async methods which could cause errors
the other one is to await all of the async methods and just using one catch block.
ill try each of them
await alone doesn't work, but catch alone does work
im confused as to why await doesn't work
because somewhere you did forgot to await the function which calls the edit part
no, i awaited every single line already
i replaced all the awaits that i did with catch and it worked
you have try / catch on the top?
ill explain to you what i did
Iโve used a command handler file to get the command file that I ran. Then, I execute the execute() function that's in every command. Every execute() function is an asynchronous function. I call await command.execute in a try catch block, and I send the error message with message.channel.send in the catch block, so I don't have to go back and forth to my console.
yeah, can I see the execute() function?
Here's the execute function, I'm testing out some interactions.
oh, you tried to await inside of an event. that's a different story
that's different?
im running command.execute in the messageCreate event, is that what you mean?
ohhh
nvm, the collect and end event?
yeah, since event will work outside of execute() function, the try catch which includes execute() won't catch the errors
oh my god so i have to surround the entire code block inside the event with try catch
or something like that
so you have to also make try / catch inside of an event
collector.on('collect', async interaction => {
try {
await interaction.deferUpdate();
if (interaction.isSelectMenu()) { test = interaction.values[0]; if (theMsg) await theMsg.edit({ content: test }) }
if (interaction.isButton()) if (theMsg) await theMsg.edit({ content: `Done: ${test}`, components: [row3] })
} catch (e) {
}
})
yep just did that
try {
await interaction.deferUpdate();
if (interaction.isSelectMenu()) { test = interaction.values[0]; if (theMsg) await theMsg.edit({ content: test }) }
if (interaction.isButton()) if (theMsg) await theMsg.edit({ content: `Done: ${test}`, components: [row3] })
} catch (err) {}```
alright! thanks for your help
maybe you can fully understand by reading some articles which explains how promises work
oh wait huh, it doesnt work still
this part lookin sus
oops i think i forgot to await
hm?
forEach is sync, which does not require await
edit() is async, which requires await to catch an error
oh wait i see what you mean
i think i was trying to delete it
and somehow added it in the wrong line
yeah, i guess so
i bet you aren't. all good?
yeah, thanks, ill update my other interactions as well now
alright