Skip to content

Commit

Permalink
programmatically grab bot user id instead of using env
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Zrimsek committed Jun 23, 2021
1 parent d48bf8d commit 3e76d2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/clients/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ export class DiscordClient {

this.client.on('ready', () => {
logger.info('Connected to Discord');
logger.info(`Logged in as: ${this.client?.user?.tag} - (${this.client?.user?.id})`);
logger.info(`Logged in as: ${this.client.user?.tag} - (${this.client.user?.id})`);
});
}

async onMessage(messageHandler: (message: Message) => void): Promise<void> {
this.client.on('message', messageHandler);
}

getBotUserId(): string {
const botUser = this.client.user;

if (botUser) {
return botUser.id;
}

return '';
}
}
3 changes: 1 addition & 2 deletions src/config/discord.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getEnvValue } from '../utils';

export default {
token: getEnvValue('DISCORD_TOKEN'),
bot_user_id: getEnvValue('DISCORD_BOT_USER_ID')
token: getEnvValue('DISCORD_TOKEN')
};
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ require('dotenv').config();

import { ADMIN_USER, BOT_NAME, COMMAND_PREFACE, LIGHT_COMMANDS, OBS_COMMANDS } from './constants';
import { CommandData, RedemptionData } from './models';
import { discordConfig, logger } from './config';
import {
handleAdminCommand,
handleHelpCommand,
Expand All @@ -16,6 +15,7 @@ import { Message } from 'discord.js';
import { PubSubRedemptionMessage } from 'twitch-pubsub-client';
import { clients } from './clients';
import { handleOBSRedemption } from './redemptions';
import { logger } from './config';
import { randomlyPadContent } from './utils';

let commandsActive = true;
Expand Down Expand Up @@ -87,7 +87,7 @@ clients.TwitchPubSub.onRedemption(async (message: PubSubRedemptionMessage) => {

clients.Discord.onMessage(async (message: Message) => {
const member = await message.guild?.members.fetch(message.author);
const isBastulosBot = member?.id === discordConfig.bot_user_id;
const isBastulosBot = member?.id === clients.Discord.getBotUserId();
const { content } = message;

if (isBastulosBot) return; // ignore messages from the bot
Expand Down

0 comments on commit 3e76d2a

Please sign in to comment.