-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(discordx): discordjs builders support (#1065)
* refactor(discordx): discordjs builders support * refactor: add doc example * refactor: bump version
- Loading branch information
1 parent
86a29fd
commit c7c1759
Showing
18 changed files
with
494 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# discordx | ||
|
||
## 11.12.0 | ||
|
||
### Minor Changes | ||
|
||
- added support for slash command builder | ||
|
||
## 11.11.3 | ||
|
||
### Patch Changes | ||
|
41 changes: 41 additions & 0 deletions
41
packages/discordx/examples/builders/commands/autocomplete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------------- | ||
* Copyright (c) Vijay Meena <[email protected]> (https://github.com/samarmeena). All rights reserved. | ||
* Licensed under the Apache License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------------------- | ||
*/ | ||
import { | ||
AutocompleteInteraction, | ||
SlashCommandBuilder, | ||
SlashCommandStringOption, | ||
type CommandInteraction, | ||
} from "discord.js"; | ||
import { Discord, Slash, SlashOption } from "discordx"; | ||
|
||
const cmd = new SlashCommandBuilder() | ||
.setName("planet-auto") | ||
.setDescription("Select a planet"); | ||
|
||
const planet_option = new SlashCommandStringOption() | ||
.setName("planet") | ||
.setDescription("Choose a planet") | ||
.setRequired(true) | ||
.setAutocomplete(true); | ||
|
||
@Discord() | ||
export class Example { | ||
@Slash(cmd) | ||
async hello( | ||
@SlashOption(planet_option) planet: string, | ||
interaction: CommandInteraction | AutocompleteInteraction, | ||
): Promise<void> { | ||
if (interaction.isAutocomplete()) { | ||
interaction.respond([ | ||
{ name: "Earth", value: "Earth" }, | ||
{ name: "Mars", value: "Mars" }, | ||
]); | ||
} else { | ||
await interaction.reply(`:rocket: going to ${planet}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------------- | ||
* Copyright (c) Vijay Meena <[email protected]> (https://github.com/samarmeena). All rights reserved. | ||
* Licensed under the Apache License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------------------- | ||
*/ | ||
import { | ||
SlashCommandBuilder, | ||
SlashCommandStringOption, | ||
type CommandInteraction, | ||
} from "discord.js"; | ||
import { Discord, Slash, SlashOption } from "discordx"; | ||
|
||
const cmd = new SlashCommandBuilder() | ||
.setName("planet") | ||
.setDescription("Select a planet"); | ||
|
||
const planet_option = new SlashCommandStringOption() | ||
.setName("planet") | ||
.setDescription("Choose a planet") | ||
.setRequired(true) | ||
.addChoices([ | ||
{ name: "Earth", value: "Earth" }, | ||
{ name: "Mars", value: "Mars" }, | ||
]); | ||
|
||
@Discord() | ||
export class Example { | ||
@Slash(cmd) | ||
async hello( | ||
@SlashOption(planet_option) planet: string, | ||
interaction: CommandInteraction, | ||
): Promise<void> { | ||
await interaction.reply(`:rocket: going to ${planet}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------------- | ||
* Copyright (c) Vijay Meena <[email protected]> (https://github.com/samarmeena). All rights reserved. | ||
* Licensed under the Apache License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------------------- | ||
*/ | ||
import { | ||
SlashCommandBuilder, | ||
SlashCommandMentionableOption, | ||
User, | ||
type CommandInteraction, | ||
} from "discord.js"; | ||
import { Discord, Slash, SlashOption } from "discordx"; | ||
|
||
const cmd = new SlashCommandBuilder() | ||
.setName("hello") | ||
.setDescription("Say hello!"); | ||
|
||
const user_option = new SlashCommandMentionableOption() | ||
.setName("user") | ||
.setDescription("Mention user to say hello to.") | ||
.setRequired(true); | ||
|
||
@Discord() | ||
export class Example { | ||
@Slash(cmd) | ||
async hello( | ||
@SlashOption(user_option) user: User, | ||
interaction: CommandInteraction, | ||
): Promise<void> { | ||
await interaction.reply(`:wave: ${user}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------------- | ||
* Copyright (c) Vijay Meena <[email protected]> (https://github.com/samarmeena). All rights reserved. | ||
* Licensed under the Apache License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------------------- | ||
*/ | ||
import { SlashCommandBuilder, type CommandInteraction } from "discord.js"; | ||
import { Discord, Slash } from "discordx"; | ||
|
||
const cmd = new SlashCommandBuilder() | ||
.setName("ping") | ||
.setDescription("Reply with pong!"); | ||
|
||
@Discord() | ||
export class Example { | ||
@Slash(cmd) | ||
async ping(interaction: CommandInteraction): Promise<void> { | ||
await interaction.reply("Pong"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------------- | ||
* Copyright (c) Vijay Meena <[email protected]> (https://github.com/samarmeena). All rights reserved. | ||
* Licensed under the Apache License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------------------- | ||
*/ | ||
import { dirname, importx } from "@discordx/importer"; | ||
import { IntentsBitField } from "discord.js"; | ||
import { Client } from "discordx"; | ||
|
||
export class Main { | ||
private static _client: Client; | ||
|
||
static get Client(): Client { | ||
return this._client; | ||
} | ||
|
||
static async start(): Promise<void> { | ||
this._client = new Client({ | ||
// botGuilds: [(client) => client.guilds.cache.map((guild) => guild.id)], | ||
intents: [ | ||
IntentsBitField.Flags.Guilds, | ||
IntentsBitField.Flags.GuildMessages, | ||
IntentsBitField.Flags.GuildMembers, | ||
], | ||
silent: false, | ||
}); | ||
|
||
this._client.once("ready", () => { | ||
// An example of how guild commands can be cleared | ||
// | ||
// await this._client.clearApplicationCommands( | ||
// ...this._client.guilds.cache.map((guild) => guild.id) | ||
// ); | ||
|
||
void this._client.initApplicationCommands(); | ||
|
||
console.log(">> Bot started"); | ||
}); | ||
|
||
this._client.on("interactionCreate", (interaction) => { | ||
this._client.executeInteraction(interaction); | ||
}); | ||
|
||
await importx(`${dirname(import.meta.url)}/commands/**/*.{js,ts}`); | ||
|
||
// let's start the bot | ||
if (!process.env.BOT_TOKEN) { | ||
throw Error("Could not find BOT_TOKEN in your environment"); | ||
} | ||
await this._client.login(process.env.BOT_TOKEN); | ||
} | ||
} | ||
|
||
void Main.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"target": "ESNext", | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"outDir": "dist", | ||
"emitDecoratorMetadata": false, | ||
"experimentalDecorators": true, | ||
"strictNullChecks": true, | ||
"noUncheckedIndexedAccess": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"moduleResolution": "Bundler", | ||
"esModuleInterop": true | ||
}, | ||
"exclude": ["node_modules", "tests", "examples"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.