From 3162de41b9bd59b442ee740e46516a09670e4910 Mon Sep 17 00:00:00 2001 From: Jack Devey Date: Sun, 7 Nov 2021 17:40:04 +0000 Subject: [PATCH] Fix multiple notifications bug --- index.ts | 5 ++--- src/Bot.ts | 10 +++++++++- src/stateUpdate.ts | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 2a660bd..78c9763 100644 --- a/index.ts +++ b/index.ts @@ -33,7 +33,8 @@ const Discord = require("discord.js"); const intents = [ Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_VOICE_STATES, - Discord.Intents.FLAGS.GUILD_MESSAGES + Discord.Intents.FLAGS.GUILD_MESSAGES, + Discord.Intents.FLAGS.DIRECT_MESSAGES ]; const commands: Command[] = [ @@ -53,8 +54,6 @@ bot.listen(function (client: Client) { console.log("BanDev | 1.0.0"); console.log("==="); console.log("AWAITING COMMANDS..."); - - client.user.setActivity('bandev.uk/notify', { type: 'PLAYING' }); }); // When something changes in a diff --git a/src/Bot.ts b/src/Bot.ts index fcfaa32..b2cd6ed 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -37,6 +37,7 @@ export class Bot { this.ready = ready; this.client.login(this.token); this.onInteraction(); + this.onMessage(); this.onReady(); } @@ -62,7 +63,14 @@ export class Bot { private onReady() { this.client.on("ready", client => { - this.ready(this.client); + client.user.setActivity('bandev.uk/notify', { type: 'PLAYING' }); + this.ready(client); + }); + } + + private onMessage() { + this.client.on("messageCreate", async message => { + console.log(message) }); } diff --git a/src/stateUpdate.ts b/src/stateUpdate.ts index dddfd79..5dfebb6 100644 --- a/src/stateUpdate.ts +++ b/src/stateUpdate.ts @@ -51,14 +51,14 @@ export function stateUpdate(discord, before, updated) { } - if(updated.streaming) { + if(updated.streaming && !before.streaming) { // User is streaming return send(discord, `${member.displayName} is live in ${updated.channel.name}`, `🔴`, member, updateChannel); } - if(updated.selfVideo) { + if(updated.selfVideo && !before.selfVideo) { // User has camera on return send(discord, `${member.displayName} turned their camera on in ${updated.channel.name}`, `📷`, member, updateChannel);