generated from lucxjo/template
Add Discordx init
Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
6c9841ced0
commit
429504787a
9 changed files with 874 additions and 0 deletions
10
src/commands/slashes.ts
Normal file
10
src/commands/slashes.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import type { CommandInteraction } from "discord.js";
|
||||
import { Discord, Slash } from "discordx";
|
||||
|
||||
@Discord()
|
||||
export class Example {
|
||||
@Slash({ description: "ping" })
|
||||
ping(interaction: CommandInteraction): void {
|
||||
interaction.reply("pong!");
|
||||
}
|
||||
}
|
||||
10
src/events/common.ts
Normal file
10
src/events/common.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import type { ArgsOf, Client } from "discordx";
|
||||
import { Discord, On } from "discordx";
|
||||
|
||||
@Discord()
|
||||
export class Example {
|
||||
@On()
|
||||
messageDelete([message]: ArgsOf<"messageDelete">, client: Client): void {
|
||||
console.log("Message Deleted", client.user?.username, message.content);
|
||||
}
|
||||
}
|
||||
71
src/main.ts
Normal file
71
src/main.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { dirname, importx } from "@discordx/importer";
|
||||
import type { Interaction, Message } from "discord.js";
|
||||
import { IntentsBitField } from "discord.js";
|
||||
import { Client } from "discordx";
|
||||
|
||||
export const bot = new Client({
|
||||
// To use only guild command
|
||||
// botGuilds: [(client) => client.guilds.cache.map((guild) => guild.id)],
|
||||
|
||||
// Discord intents
|
||||
intents: [
|
||||
IntentsBitField.Flags.Guilds,
|
||||
IntentsBitField.Flags.GuildMembers,
|
||||
IntentsBitField.Flags.GuildMessages,
|
||||
IntentsBitField.Flags.GuildMessageReactions,
|
||||
IntentsBitField.Flags.GuildVoiceStates,
|
||||
],
|
||||
|
||||
// Debug logs are disabled in silent mode
|
||||
silent: false,
|
||||
|
||||
// Configuration for @SimpleCommand
|
||||
simpleCommand: {
|
||||
prefix: "!",
|
||||
},
|
||||
});
|
||||
|
||||
bot.once("ready", async () => {
|
||||
// Make sure all guilds are cached
|
||||
// await bot.guilds.fetch();
|
||||
|
||||
// Synchronize applications commands with Discord
|
||||
await bot.initApplicationCommands();
|
||||
|
||||
// To clear all guild commands, uncomment this line,
|
||||
// This is useful when moving from guild commands to global commands
|
||||
// It must only be executed once
|
||||
//
|
||||
// await bot.clearApplicationCommands(
|
||||
// ...bot.guilds.cache.map((g) => g.id)
|
||||
// );
|
||||
|
||||
console.log("Bot started");
|
||||
});
|
||||
|
||||
bot.on("interactionCreate", (interaction: Interaction) => {
|
||||
bot.executeInteraction(interaction);
|
||||
});
|
||||
|
||||
bot.on("messageCreate", (message: Message) => {
|
||||
bot.executeCommand(message);
|
||||
});
|
||||
|
||||
async function run() {
|
||||
// The following syntax should be used in the commonjs environment
|
||||
//
|
||||
// await importx(__dirname + "/{events,commands}/**/*.{ts,js}");
|
||||
|
||||
// The following syntax should be used in the ECMAScript environment
|
||||
await importx(`${dirname(import.meta.url)}/{events,commands}/**/*.{ts,js}`);
|
||||
|
||||
// Let's start the bot
|
||||
if (!process.env.BOT_TOKEN) {
|
||||
throw Error("Could not find BOT_TOKEN in your environment");
|
||||
}
|
||||
|
||||
// Log in with your bot token
|
||||
await bot.login(process.env.BOT_TOKEN);
|
||||
}
|
||||
|
||||
run();
|
||||
Loading…
Add table
Add a link
Reference in a new issue