mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 08:20:08 +00:00
fix: bot id optional on createBot
This commit is contained in:
6
bot.ts
6
bot.ts
@@ -137,11 +137,11 @@ import {
|
||||
} from "./transformers/applicationCommandOptionChoice.ts";
|
||||
import { transformEmbedToDiscordEmbed } from "./transformers/reverse/embed.ts";
|
||||
import { transformComponentToDiscordComponent } from "./transformers/reverse/component.ts";
|
||||
import { removeTokenPrefix } from "./util/token.ts";
|
||||
import { getBotIdFromToken, removeTokenPrefix } from "./util/token.ts";
|
||||
|
||||
export function createBot(options: CreateBotOptions): Bot {
|
||||
const bot = {
|
||||
id: options.botId,
|
||||
id: options.botId ?? getBotIdFromToken(options.token),
|
||||
applicationId: options.applicationId || options.botId,
|
||||
token: removeTokenPrefix(options.token),
|
||||
events: createEventHandlers(options.events ?? {}),
|
||||
@@ -314,7 +314,7 @@ export async function stopBot(bot: Bot) {
|
||||
|
||||
export interface CreateBotOptions {
|
||||
token: string;
|
||||
botId: bigint;
|
||||
botId?: bigint;
|
||||
applicationId?: bigint;
|
||||
secretKey?: string;
|
||||
events?: Partial<EventHandlers>;
|
||||
|
||||
@@ -7,3 +7,8 @@ export function removeTokenPrefix(token?: string, type: "GATEWAY" | "REST" = "RE
|
||||
// Remove the prefix and return only the token.
|
||||
return token.substring(token.indexOf(" ") + 1);
|
||||
}
|
||||
|
||||
/** Get the bot id from the bot token. WARNING: Discord staff has mentioned this may not be stable forever. Use at your own risk. However, note for over 5 years this has never broken. */
|
||||
export function getBotIdFromToken(token: string) {
|
||||
return BigInt(atob(token.split(".")[0]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user