respond with command list when @mentioned

This commit is contained in:
GooeyTuxedo 2023-04-18 14:47:06 -07:00
parent 6036aea919
commit bfaa6ebd25
5 changed files with 44 additions and 18 deletions

View File

@ -2,23 +2,23 @@ import { Events, Interaction } from 'discord.js';
import { DiscordClient } from '../discordClient'; import { DiscordClient } from '../discordClient';
module.exports = { module.exports = {
name: Events.InteractionCreate, name: Events.InteractionCreate,
async execute(interaction: Interaction) { async execute(interaction: Interaction) {
if (!interaction.isChatInputCommand()) return; if (!interaction.isChatInputCommand()) return;
const client = interaction.client as DiscordClient; const client = interaction.client as DiscordClient;
const command = client.commands.get(interaction.commandName); const command = client.commands.get(interaction.commandName);
if (!command) { if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`); console.error(`No command matching ${interaction.commandName} was found.`);
return; return;
} }
try { try {
await command.execute(interaction); await command.execute(interaction);
} catch (error) { } catch (error) {
console.error(`Error executing ${interaction.commandName}`); console.error(`Error executing ${interaction.commandName}`);
console.error(error); console.error(error);
} }
}, }
}; };

24
src/events/message.ts Normal file
View File

@ -0,0 +1,24 @@
import 'dotenv/config.js';
import { Events, Message, EmbedBuilder, User } from "discord.js";
import { DiscordClient } from '../discordClient';
module.exports = {
name: Events.MessageCreate,
async execute(client: DiscordClient, message: Message) {
if (message.author.bot) return;
if (message.mentions.has(client.user as User)) {
const embeds = [
new EmbedBuilder()
.setColor('#008000')
.setTitle('Available slash commands')
.setDescription(
`/gas
/alert [GWEI]
/alert-delete
/pending-alert`
)
]
message.reply({embeds});
}
}
};

View File

@ -5,6 +5,6 @@ module.exports = {
name: Events.ClientReady, name: Events.ClientReady,
once: true, once: true,
execute(client: DiscordClient) { execute(client: DiscordClient) {
if (client.user) return console.log(`Ready! Logged in as ${client.user.tag}`); if (client.user) return console.log(`Ready! Logged in as ${client.user.id}: ${client.user.tag}`);
} }
}; };

View File

@ -13,7 +13,7 @@ const handleGasCommand = async (interaction: ChatInputCommandInteraction): Promi
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setColor('#0099ff') .setColor('#0099ff')
.setTitle('Current Gas Prices') .setTitle('Current Gas Prices')
.setDescription(`The current gas prices are: \n\n Fast: ${gasPrices.fast} Gwei \n\n Average: ${gasPrices.average} Gwei \n\n Slow: ${gasPrices.slow} Gwei`) .setDescription(`${gasPrices.fast} ⦚⦚ 🚶${gasPrices.average} ⦚⦚ 🐢${gasPrices.slow}`)
await interaction.reply({ embeds: [embed] }); await interaction.reply({ embeds: [embed] });
}; };

View File

@ -44,6 +44,8 @@ for (const file of eventFiles) {
const event = require(filePath); const event = require(filePath);
if (event.once) { if (event.once) {
client.once(event.name, (...args) => event.execute(...args)); client.once(event.name, (...args) => event.execute(...args));
} else if (event.name == 'messageCreate') {
client.on(event.name, (...args) => event.execute(client, ...args));
} else { } else {
client.on(event.name, (...args) => event.execute(...args)); client.on(event.name, (...args) => event.execute(...args));
} }