I like to browse the Discord tag and solve questions where I can. I'm fairly fluent in Python but only passable in Javascript, but I do throw my hat in the ring sometimes.
The Discord.py library has many functions that must be awaited. Failing to do so will not run.
The Discord.js library returns many promises for different things, and as I was writing answers involving those it was natural for me to add await. I also looked up a tutorial to see best practice for writing async/await in Discord.js.
Further, adding await required me to make my event handlers async, irrationally reinforcing my belief these await statements needed to exist.
client.on('message', async message => {
await message.member.edit({mute: true})
});
This all works well and good, and I foolishly began recommending others do the same. However, in reading questions and writing answers, I've stumbled on something befuddling to me.
client.on('message', message => {
let memberArray = [message.member];
memberArray.forEach(member => member.edit({mute: true}));
console.log("Do something after promised mute");
});
This code, with no async function nor awaited promise, still runs. This seems weird to me (what is the point of awaiting if the code can be executed, seemingly in sync order, without it?).
Continuing the confuse streak, I can make this function async and still run it without awaiting the promise. The only thing that will cause an error is an await statement in a synchronous function.
The other possibility is that this is unsafe and going to cause problems in production, but since my test bot only interacts with one user (me) doing 1 thing at a time, I can't see the problem. Does Node.js just let me run bad code without warning me? Have I overthought/overengineered a non-problem? What's the deal with airline food?