Skip to content

Commit

Permalink
feat: Connect to Discord via DiscordConnection instead of `Discord.…
Browse files Browse the repository at this point in the history
…createBot()`.
  • Loading branch information
vxern committed Oct 19, 2024
1 parent 5913af0 commit 0352933
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions scripts/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DatabaseMetadata } from "logos/models/database-metadata";
import { Guild } from "logos/models/guild";
import { CacheStore } from "logos/stores/cache";
import { DatabaseStore } from "logos/stores/database";
import { DiscordConnection } from "logos/connection";

const log = constants.loggers.feedback;

Expand Down Expand Up @@ -33,14 +34,13 @@ async function getInviteCode({ guildId }: { guildId: bigint }): Promise<string |
}

const environment = loadEnvironment({ log: constants.loggers.silent });
const bot = Discord.createBot({
token: environment.discordSecret,
const connection = new DiscordConnection({
environment,
intents: Discord.Intents.Guilds | Discord.Intents.GuildMembers,
events: {},
defaultDesiredPropertiesValue: true,
});
const bot = connection.bot;

bot.start();
await connection.open();

const database = DatabaseStore.create({
log: constants.loggers.silent,
Expand Down
15 changes: 8 additions & 7 deletions source/library/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@ class DiscordConnection {
constructor({
log = constants.loggers.silent,
environment,
intents = Discord.Intents.Guilds |
Discord.Intents.GuildMembers |
Discord.Intents.GuildModeration |
Discord.Intents.GuildVoiceStates |
Discord.Intents.GuildMessages |
Discord.Intents.MessageContent,
eventHandlers = {},
cacheHandlers = {},
}: {
log?: pino.Logger;
environment: Environment;
intents?: Discord.GatewayIntents;
eventHandlers?: Partial<Discord.EventHandlers>;
cacheHandlers?: Partial<Discord.Transformers["customizers"]>;
}) {
this.log = log.child({ name: "DiscordConnection" });
this.bot = Discord.createBot({
token: environment.discordSecret,
intents:
Discord.Intents.Guilds |
Discord.Intents.GuildMembers |
Discord.Intents.GuildModeration |
Discord.Intents.GuildVoiceStates |
Discord.Intents.GuildMessages |
Discord.Intents.MessageContent,
intents,
events: eventHandlers,
// REMINDER(vxern): Remove this once the bot is updated to a newer Discordeno release.
//
Expand Down

0 comments on commit 0352933

Please sign in to comment.