#huh both awaiting and using catch isn t

1 messages ยท Page 1 of 1 (latest)

carmine moth
#

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.

tough harbor
#

ill try each of them

#

await alone doesn't work, but catch alone does work

#

im confused as to why await doesn't work

carmine moth
#

because somewhere you did forgot to await the function which calls the edit part

tough harbor
#

no, i awaited every single line already

#

i replaced all the awaits that i did with catch and it worked

carmine moth
#

you have try / catch on the top?

tough harbor
#

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.

carmine moth
#

yeah, can I see the execute() function?

tough harbor
carmine moth
tough harbor
#

that's different?

#

im running command.execute in the messageCreate event, is that what you mean?

#

ohhh

#

nvm, the collect and end event?

carmine moth
#

yeah, since event will work outside of execute() function, the try catch which includes execute() won't catch the errors

tough harbor
#

or something like that

carmine moth
#

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) {
            
        }
    })
tough harbor
#

alright! thanks for your help

carmine moth
#

aight

#

good luck ๐Ÿ‘

tough harbor
#

ill keep this in mind when i do something like this next time

#

thanks again

carmine moth
#

maybe you can fully understand by reading some articles which explains how promises work

carmine moth
tough harbor
carmine moth
#

you don't need to await for sync tasks

#

and you forgot to await the asnyc task

tough harbor
#

hm?

carmine moth
#

forEach is sync, which does not require await

#

edit() is async, which requires await to catch an error

tough harbor
#

oh wait i see what you mean

#

i think i was trying to delete it

#

and somehow added it in the wrong line

carmine moth
#

yeah, i guess so

tough harbor
#

ah yes, it works

#

i am an absolute idiot and lazy kid

carmine moth
#

i bet you aren't. all good?

tough harbor
#

yeah, thanks, ill update my other interactions as well now

carmine moth
#

alright