Skip to content

Commit

Permalink
chore: cr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Q1w1N committed Dec 5, 2024
1 parent cea9c91 commit ccbd1c8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .changeset/cuddly-mangos-train.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
'discord-example': minor
---

added start function to abstract away passing bot token
changed passing bot token variable and discord login
3 changes: 1 addition & 2 deletions examples/discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ const app = createApp({

const discordClient = await createDiscordApp({
app,
botToken: DISCORD_BOT_TOKEN,
});

void (async () => {
try {
await discordClient.start();
await discordClient.login(DISCORD_BOT_TOKEN);
logger.info('Discord ready.');
} catch (error) {
logger.error('Dev Slack start error:', error);
Expand Down
17 changes: 3 additions & 14 deletions packages/discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ const UPDATE_THROTTLE_TIME = 200;

export type DiscordApplicationConfig = {
app: Application;
botToken: string;
};

type ClientStart = {
start: () => Promise<string>;
};

export type DiscordClient = Client & ClientStart;

export function createDiscordApp(options: DiscordApplicationConfig): DiscordClient {
const { app, botToken } = options;
export function createDiscordApp(options: DiscordApplicationConfig) {
const { app } = options;

const client = new Client({
intents: [
Expand All @@ -26,7 +19,7 @@ export function createDiscordApp(options: DiscordApplicationConfig): DiscordClie
GatewayIntentBits.GuildMessages,
],
partials: [Partials.Channel],
}) as DiscordClient;
});

client.once(Events.ClientReady, (readyClient) => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
Expand Down Expand Up @@ -82,10 +75,6 @@ export function createDiscordApp(options: DiscordApplicationConfig): DiscordClie
await pendingEffects;
});

client.start = () => {
return client.login(botToken);
};

return client;
}

Expand Down

0 comments on commit ccbd1c8

Please sign in to comment.