Convert to Typescript
This commit is contained in:
35
src/index.ts
Normal file
35
src/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'dotenv/config';
|
||||
import {
|
||||
Client,
|
||||
Collection,
|
||||
Events,
|
||||
GatewayIntentBits,
|
||||
Interaction,
|
||||
} from 'discord.js';
|
||||
import { commands } from './commands';
|
||||
|
||||
// Define an extended version of the Client interface to include commands
|
||||
interface ExtendedClient extends Client {
|
||||
commands: Collection<string, any>;
|
||||
}
|
||||
|
||||
const client: ExtendedClient = new Client({
|
||||
intents: [GatewayIntentBits.Guilds],
|
||||
}) as ExtendedClient;
|
||||
|
||||
// Register the event listener for command interactions.
|
||||
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const { commandName } = interaction;
|
||||
|
||||
if (commands[commandName as keyof typeof commands]) {
|
||||
commands[commandName as keyof typeof commands].execute(interaction);
|
||||
}
|
||||
});
|
||||
|
||||
client.once(Events.ClientReady, (readyClient) => {
|
||||
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_API_KEY);
|
||||
Reference in New Issue
Block a user