discordeno icon indicating copy to clipboard operation
discordeno copied to clipboard

Show a better error when `applicationId` is not set

Open jespertheend opened this issue 2 years ago • 8 comments

Is your feature request related to a problem? Please describe. I tried to bot.helpers.upsertApplicationCommands() but was greeted with an unhelpful error message:

Error: [400] The request was improperly formatted, or the server couldn't understand it.

After debugging, I found out that this was because a request was being sent to /applications/undefined/commands. Only then I realised I had to provide an applicationId in createBot().

Describe the solution you'd like

I think it would be better if an error is thrown somewhere either in createBot() or in upsertApplicationCommands() indicating that an application id needs to be set. Either that or the applicationId field should not be optional in the createBot() types.

Describe alternatives you've considered The only alternative I can think of is to just deal with it.

jespertheend avatar Jul 06 '22 12:07 jespertheend

There is a function with whom, you can overwrite the error

rest.convertError(error, data){
      console.log(data)
}

meister03 avatar Jul 06 '22 16:07 meister03

Hmm there's little point for me to do that, as I'm already aware of the need for applicationId to be set. This feature request was really meant for new users of the library. And since /applications/undefined/commands should basically never be sent to the Discord API, it would be much better if the library would just throw immediately rather than sending a broken request.

jespertheend avatar Jul 06 '22 16:07 jespertheend

The checks will probably slowdown the process & moreover the applicationId is a required type, where as you should get a type error

meister03 avatar Jul 18 '22 15:07 meister03

I didn't get a type error, seems like it's marked as optional in CreateBotOptions.

https://github.com/discordeno/discordeno/blob/03996c5f5816b094891122f2e904d770131aa0fd/bot.ts#L329

jespertheend avatar Jul 18 '22 17:07 jespertheend

I didn't get a type error, seems like it's marked as optional in CreateBotOptions.

https://github.com/discordeno/discordeno/blob/03996c5f5816b094891122f2e904d770131aa0fd/bot.ts#L329 which version are you using?

meister03 avatar Jul 18 '22 17:07 meister03

I'm importing discordeno from https://deno.land/x/[email protected]/mod.ts

import {
	createBot,
	Intents,
} from "https://deno.land/x/[email protected]/mod.ts";

const token = Deno.env.get("DISCORD_TOKEN");
if (!token) {
	throw new Error("Make sure the DISCORD_TOKEN environment variable is set");
}

const bot = createBot({
	token,
	intents: Intents.Guilds | Intents.GuildMessages,
});

jespertheend avatar Jul 18 '22 17:07 jespertheend

It seems like the applicationId is set as soon the bot is ready. The problem is that parsing it from the token, that some bots have a different applicationId in comparision to their botid

meister03 avatar Jul 18 '22 17:07 meister03

@jespertheend That shouldn't happen because application is parsed from bot id

lts20050703 avatar Jul 26 '22 05:07 lts20050703

Thank you for reporting, should be patched so it is never undefined again so a better error won't be needed anymore.

Skillz4Killz avatar Aug 25 '22 15:08 Skillz4Killz