Skip to content

Commit 3d41613

Browse files
committed
update: Updated command loggers to use webhooks now instead of channelID's
1 parent 6b5733f commit 3d41613

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

.development.example.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ guildid=
44
devid=
55
mongodb=
66
movietrackerapi=
7-
rapidapikey=
7+
rapidapikey=
8+
9+
webhookSlashLogging="",
10+
webhookPrefixLogging="",

.example.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ guildid=
44
devid=
55
mongodb=
66
movietrackerapi=
7-
rapidapikey=
7+
rapidapikey=
8+
9+
webhookSlashLogging="",
10+
webhookPrefixLogging="",

src/config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ module.exports = {
5454
musicEmojiError: "❌",
5555

5656
// CHANNEL IDS //
57-
slashCommandLoggingChannel: "1238869804744441896", // slash command logging channel
58-
prefixCommandLoggingChannel: "1241592178480775188", // Prefix command logging channel
5957
suggestionChannel: "1240335460463677503", // Suggestion channel
6058
bugReportChannel: "1240341717031456840", // Bug report channel
6159
botLeaveChannel: "1139731092329480332", // Logging channel for bot leaving servers

src/events/CommandLoggingEvents/prefixCommandLogging.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { Events, EmbedBuilder } = require('discord.js');
1+
const { Events, EmbedBuilder, WebhookClient } = require('discord.js');
22

33
module.exports = {
44
name: Events.MessageCreate,
@@ -7,7 +7,7 @@ module.exports = {
77
const guildPrefix = client.config.prefix;
88
if (!message.author.bot && message.content.startsWith(guildPrefix)) {
99

10-
const channel = await client.channels.cache.get(client.config.prefixCommandLoggingChannel);
10+
const webhookURL = process.env.webhookPrefixLogging;
1111
const server = message.guild.name;
1212
const user = message.author.username;
1313
const userID = message.author.id;
@@ -22,7 +22,17 @@ module.exports = {
2222
.setTimestamp()
2323
.setFooter({ text: `Command Logger ${client.config.devBy}`, iconURL: message.author.avatarURL({ dynamic: true }) })
2424

25-
await channel.send({ embeds: [embed] });
25+
try {
26+
const webhookClient = new WebhookClient({ url: webhookURL });
27+
28+
await webhookClient.send({
29+
embeds: [embed],
30+
username: `${client.user.username} Prefix Command Logger`,
31+
avatarURL: client.user.avatarURL(),
32+
});
33+
} catch (error) {
34+
client.logs.error('[COMMAND_PREFIX_LOGGING_WEBHOOK] Error whilst sending webhook:', error);
35+
}
2636
}
2737
}
2838
}

src/events/CommandLoggingEvents/slashCommandLogging.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { Events, EmbedBuilder } = require('discord.js');
1+
const { Events, EmbedBuilder, WebhookClient } = require('discord.js');
22

33
module.exports = {
44
name: Events.InteractionCreate,
@@ -8,7 +8,7 @@ module.exports = {
88
if (!interaction.isChatInputCommand()) return;
99
else {
1010

11-
const channel = await client.channels.cache.get(client.config.slashCommandLoggingChannel);
11+
const webhookURL = process.env.webhookSlashLogging;
1212
const server = interaction.guild.name;
1313
const user = interaction.user.username;
1414
const userID = interaction.user.id;
@@ -23,7 +23,17 @@ module.exports = {
2323
.setTimestamp()
2424
.setFooter({ text: `Command Logger ${client.config.devBy}`, iconURL: interaction.user.avatarURL({ dynamic: true })})
2525

26-
await channel.send({ embeds: [embed] });
26+
try {
27+
const webhookClient = new WebhookClient({ url: webhookURL });
28+
29+
await webhookClient.send({
30+
embeds: [embed],
31+
username: `${client.user.username} SlashCommand Logger`,
32+
avatarURL: client.user.avatarURL(),
33+
});
34+
} catch (error) {
35+
client.logs.error('[COMMAND_SLASH_LOGGING_WEBHOOK] Error whilst sending webhook:', error);
36+
}
2737
}
2838
}
2939
}

0 commit comments

Comments
 (0)