File tree Expand file tree Collapse file tree 10 files changed +92
-92
lines changed
packages/create-discord-bot/template Expand file tree Collapse file tree 10 files changed +92
-92
lines changed Original file line number Diff line number Diff line change 1+ import { Events } from 'npm:discord.js@^14.19.3' ;
2+ import type { Event } from './index.ts' ;
3+ import { loadCommands } from '../util/loaders.ts' ;
4+
5+ const commands = await loadCommands ( new URL ( '../commands/' , import . meta. url ) ) ;
6+
7+ export default {
8+ name : Events . InteractionCreate ,
9+ async execute ( interaction ) {
10+ if ( interaction . isCommand ( ) ) {
11+ const command = commands . get ( interaction . commandName ) ;
12+
13+ if ( ! command ) {
14+ throw new Error ( `Command '${ interaction . commandName } ' not found.` ) ;
15+ }
16+
17+ await command . execute ( interaction ) ;
18+ }
19+ } ,
20+ } satisfies Event < Events . InteractionCreate > ;
Original file line number Diff line number Diff line change 11import 'https://deno.land/[email protected] /dotenv/load.ts' ; 22import { URL } from 'node:url' ;
33import { Client , GatewayIntentBits } from 'npm:discord.js@^14.19.3' ;
4- import { loadCommands , loadEvents } from './util/loaders.ts' ;
5- import { registerEvents } from './util/registerEvents.ts' ;
4+ import { loadEvents } from './util/loaders.ts' ;
65
76// Initialize the client
87const client = new Client ( { intents : [ GatewayIntentBits . Guilds ] } ) ;
98
109// Load the events and commands
1110const events = await loadEvents ( new URL ( 'events/' , import . meta. url ) ) ;
12- const commands = await loadCommands ( new URL ( 'commands/' , import . meta. url ) ) ;
1311
1412// Register the event handlers
15- registerEvents ( commands , events , client ) ;
13+ for ( const event of events ) {
14+ client [ event . once ? 'once' : 'on' ] ( event . name , async ( ...args ) => {
15+ try {
16+ await event . execute ( ...args ) ;
17+ } catch ( error ) {
18+ console . error ( `Error executing event ${ String ( event . name ) } :` , error ) ;
19+ }
20+ } ) ;
21+ }
1622
1723// Login to the client
1824void client . login ( Deno . env . get ( 'DISCORD_TOKEN' ) ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ export const schema = z.object({
2323/**
2424 * Defines the predicate to check if an object is a valid Event type.
2525 *
26- * @type {import('../util/loaders').StructurePredicate<Event> }
26+ * @type {import('../util/loaders.js ').StructurePredicate<Event> }
2727 * @returns {structure is Event }
2828 */
2929export const predicate = ( structure ) => schema . safeParse ( structure ) . success ;
Original file line number Diff line number Diff line change 1+ import { Events } from 'discord.js' ;
2+ import { loadCommands } from '../util/loaders.js' ;
3+
4+ const commands = await loadCommands ( new URL ( '../commands/' , import . meta. url ) ) ;
5+
6+ /** @type {import('../events/index.js').Event<Events.InteractionCreate> } */
7+ export default {
8+ name : Events . InteractionCreate ,
9+ async execute ( interaction ) {
10+ if ( interaction . isCommand ( ) ) {
11+ const command = commands . get ( interaction . commandName ) ;
12+
13+ if ( ! command ) {
14+ throw new Error ( `Command '${ interaction . commandName } ' not found.` ) ;
15+ }
16+
17+ await command . execute ( interaction ) ;
18+ }
19+ } ,
20+ } ;
Original file line number Diff line number Diff line change 11import process from 'node:process' ;
22import { URL } from 'node:url' ;
33import { Client , GatewayIntentBits } from 'discord.js' ;
4- import { loadCommands , loadEvents } from './util/loaders.js' ;
5- import { registerEvents } from './util/registerEvents.js' ;
4+ import { loadEvents } from './util/loaders.js' ;
65
76// Initialize the client
87const client = new Client ( { intents : [ GatewayIntentBits . Guilds ] } ) ;
98
109// Load the events and commands
1110const events = await loadEvents ( new URL ( 'events/' , import . meta. url ) ) ;
12- const commands = await loadCommands ( new URL ( 'commands/' , import . meta. url ) ) ;
1311
1412// Register the event handlers
15- registerEvents ( commands , events , client ) ;
13+ for ( const event of events ) {
14+ client [ event . once ? 'once' : 'on' ] ( event . name , async ( ...args ) => {
15+ try {
16+ await event . execute ( ...args ) ;
17+ } catch ( error ) {
18+ console . error ( `Error executing event ${ String ( event . name ) } :` , error ) ;
19+ }
20+ } ) ;
21+ }
1622
1723// Login to the client
1824void client . login ( process . env . DISCORD_TOKEN ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { URL } from 'node:url' ;
2+ import { Events } from 'discord.js' ;
3+ import { loadCommands } from '../util/loaders.[REPLACE_IMPORT_EXT]' ;
4+ import type { Event } from './index.[REPLACE_IMPORT_EXT]' ;
5+
6+ const commands = await loadCommands ( new URL ( '../commands/' , import . meta. url ) ) ;
7+
8+ export default {
9+ name : Events . InteractionCreate ,
10+ async execute ( interaction ) {
11+ if ( interaction . isCommand ( ) ) {
12+ const command = commands . get ( interaction . commandName ) ;
13+
14+ if ( ! command ) {
15+ throw new Error ( `Command '${ interaction . commandName } ' not found.` ) ;
16+ }
17+
18+ await command . execute ( interaction ) ;
19+ }
20+ } ,
21+ } satisfies Event < Events . InteractionCreate > ;
Original file line number Diff line number Diff line change 11import process from 'node:process' ;
22import { URL } from 'node:url' ;
33import { Client , GatewayIntentBits } from 'discord.js' ;
4- import { loadCommands , loadEvents } from './util/loaders.[REPLACE_IMPORT_EXT]' ;
5- import { registerEvents } from './util/registerEvents.[REPLACE_IMPORT_EXT]' ;
4+ import { loadEvents } from './util/loaders.[REPLACE_IMPORT_EXT]' ;
65
76// Initialize the client
87const client = new Client ( { intents : [ GatewayIntentBits . Guilds ] } ) ;
98
109// Load the events and commands
1110const events = await loadEvents ( new URL ( 'events/' , import . meta. url ) ) ;
12- const commands = await loadCommands ( new URL ( 'commands/' , import . meta. url ) ) ;
1311
1412// Register the event handlers
15- registerEvents ( commands , events , client ) ;
13+ for ( const event of events ) {
14+ client [ event . once ? 'once' : 'on' ] ( event . name , async ( ...args ) => {
15+ try {
16+ await event . execute ( ...args ) ;
17+ } catch ( error ) {
18+ console . error ( `Error executing event ${ String ( event . name ) } :` , error ) ;
19+ }
20+ } ) ;
21+ }
1622
1723// Login to the client
1824void client . login ( process . env . DISCORD_TOKEN ) ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments