discordeno
discordeno copied to clipboard
Show a better error when `applicationId` is not set
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.
There is a function with whom, you can overwrite the error
rest.convertError(error, data){
console.log(data)
}
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.
The checks will probably slowdown the process & moreover the applicationId is a required type, where as you should get a type error
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
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?
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,
});
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
@jespertheend That shouldn't happen because application is parsed from bot id
Thank you for reporting, should be patched so it is never undefined again so a better error won't be needed anymore.