mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-12 11:56:06 -05:00
slash commands integrated
* sample env and late version incr * added slash command compatibility * updated command name * updated environment sample * updated interaction comment
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { Event } from '../utils/index.js'
|
||||
import interactionCreate from './interactionCreate.js'
|
||||
import messageCreate from './messageCreate.js'
|
||||
import ready from './ready.js'
|
||||
|
||||
// Centralized export for all events
|
||||
export default [
|
||||
ready,
|
||||
messageCreate
|
||||
messageCreate,
|
||||
interactionCreate
|
||||
] as Event[] // staticly is better ts practice, dynamic exporting is possible
|
||||
19
src/events/interactionCreate.ts
Normal file
19
src/events/interactionCreate.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { event, Events } from '../utils/index.js'
|
||||
import commands from '../commands/index.js'
|
||||
|
||||
/**
|
||||
* Interaction creation listener for the client
|
||||
* @param interaction the interaction received from the server
|
||||
*/
|
||||
export default event(Events.InteractionCreate, async ({ log, client }, interaction) => {
|
||||
if (!interaction.isCommand() || !interaction.isChatInputCommand()) return
|
||||
|
||||
log(`Interaction called \'${interaction.commandName}\' from ${interaction.client.user.tag}.`)
|
||||
|
||||
// ensure command exists, otherwise kill event
|
||||
const command = commands.find(command => command.name === interaction.commandName)
|
||||
if (!command) return
|
||||
|
||||
// the command exists, execute it
|
||||
command.run(client, interaction)
|
||||
})
|
||||
@@ -14,7 +14,7 @@ export default event(Events.MessageCreate, async ({ log, msgHist, tokens }, mess
|
||||
if (message.author.tag === message.client.user.tag) return
|
||||
|
||||
// Only respond if message mentions the bot
|
||||
if (!message.mentions.has(tokens.botUid)) return
|
||||
if (!message.mentions.has(tokens.clientUid)) return
|
||||
|
||||
// push user response
|
||||
msgHist.push({
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
import { event, Events } from '../utils/index.js'
|
||||
import { event, Events, registerCommands } from '../utils/index.js'
|
||||
import { ActivityType } from 'discord.js'
|
||||
import commands from '../commands/index.js'
|
||||
|
||||
// Log when the bot successfully logs in and export it
|
||||
export default event(Events.ClientReady, ({ log }, client) => {
|
||||
return log(`Logged in as ${client.user.username}.`)
|
||||
log(`Logged in as ${client.user.username}.`)
|
||||
|
||||
// Register the commands associated with the bot upon loggin in
|
||||
registerCommands(client, commands)
|
||||
|
||||
// set status of the bot
|
||||
client.user.setActivity({
|
||||
name: 'Powered by Ollama',
|
||||
type: ActivityType.Custom
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user