Skip to content

Commit

Permalink
fix: fix message sending issue on bot add
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Nov 12, 2023
1 parent 3cfbbf5 commit 361f9d2
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/InterChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class InterChat extends SuperClient {
);
});


this.on('shardReady', (shard) => {
this.logger.info(`Shard ${shard} is ready!`);
});
Expand Down Expand Up @@ -127,12 +126,21 @@ class InterChat extends SuperClient {
.setColor(colors.invisible)
.setFooter({ text: `Sent for: ${guild.name}`, iconURL: guild.iconURL() || undefined });

const firstChannel = guild.channels.cache
.filter(
(c) =>
c.type === ChannelType.GuildText && c.permissionsFor(guild.id)?.has('SendMessages'),
)
.first() as TextChannel;

if (guild.members.me?.permissions.has('ViewAuditLog')) {
const auditLog = await guild.fetchAuditLogs({ type: AuditLogEvent.BotAdd, limit: 5 });
const entry = auditLog.entries.first();

// send message to the person who added the bot
await entry?.executor?.send({ embeds: [embed], components: [buttons] }).catch(() => null);
await entry?.executor?.send({ embeds: [embed], components: [buttons] }).catch(() => {
firstChannel.send({ embeds: [embed], components: [buttons] }).catch(() => null);
});

if (isProfane) {
await entry?.executor?.send({ embeds: [profaneErrorEmbed] }).catch(() => null);
Expand All @@ -141,13 +149,6 @@ class InterChat extends SuperClient {
}
}
else {
const firstChannel = guild.channels.cache
.filter(
(c) =>
c.type === ChannelType.GuildText && c.permissionsFor(guild.id)?.has('SendMessages'),
)
.first() as TextChannel;

if (isProfane) {
await firstChannel?.send({ embeds: [profaneErrorEmbed] }).catch(() => null);
await guild.leave();
Expand Down

0 comments on commit 361f9d2

Please sign in to comment.