Skip to content

Commit

Permalink
update stats on joining and leaving guilds
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryAllen1 committed Dec 27, 2021
1 parent 9b3afce commit f24bee6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/events/guild/GuildCreateEvent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-guildCreate
import { Guild } from 'discord.js';
import { Guild, MessageActionRow, MessageButton } from 'discord.js';
import BaseEvent from '../../utils/structures/BaseEvent.js';
import DiscordClient from '../../client/client.js';
import { log } from '../../utils/helpers/console.js';
Expand All @@ -11,6 +11,10 @@ export default class GuildCreateEvent extends BaseEvent {
}

async run(client: DiscordClient, guild: Guild) {
client.user?.setActivity({
name: `$help in ${client.guilds.cache.size} servers`,
type: 'WATCHING',
});
client.users.cache
.get('696554549418262548')
?.send(
Expand All @@ -27,8 +31,8 @@ export default class GuildCreateEvent extends BaseEvent {
guild.me?.permissions.has('VIEW_CHANNEL') &&
guild.systemChannel?.permissionsFor(guild.me).has('SEND_MESSAGES') &&
guild.systemChannel?.permissionsFor(guild.me).has('VIEW_CHANNEL')
)
guild.systemChannel?.send({
) {
const msg = await guild.systemChannel?.send({
embeds: [
{
title: 'Hello, I am Sniper',
Expand All @@ -47,6 +51,29 @@ export default class GuildCreateEvent extends BaseEvent {
],
},
],
components: [
new MessageActionRow().addComponents(
new MessageButton()
.setEmoji('❌')
.setCustomId('remove')
.setStyle('PRIMARY')
),
],
});
msg
.createMessageComponentCollector({ componentType: 'BUTTON' })
.on('collect', (i) => {
i.deferUpdate();
if (!i.memberPermissions?.has('MANAGE_MESSAGES'))
return i.reply({
content:
'You cannot delete this messages since you dont have the manage messages permission.',
ephemeral: true,
});
else {
msg.delete();
}
});
}
}
}
4 changes: 4 additions & 0 deletions src/events/guild/GuildDeleteEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default class GuildDeleteEvent extends BaseEvent {
}

async run(client: DiscordClient, guild: Guild) {
client.user?.setActivity({
name: `$help in ${client.guilds.cache.size} servers`,
type: 'WATCHING',
});
log(
chalk.redBright(
`Left server ${guild.name}. Now in ${client.guilds.cache.size} guilds.`
Expand Down

0 comments on commit f24bee6

Please sign in to comment.