New slash command related events:
these are all emitted by the command handler
- slashError
- slashBlocked
- owner
- superuser
- slashStarted
- slashNotFound
- slashGuildOnly
- slashMissingPermissions
- user
- client
New normal events
- notNsfw
Cooldown event will also run on slash commands
For more info about these events view the source code. If you don't want to do that, you can safely assume that they are the exact same as their non-slash versions, execpt all Message
arguments are changed to CommandInteraction
.
Slash command example:
Slash commands are turned into message like objects to make interacting with them easier the original ineraction is maintained though at message.interaction, please note that you will need to register the slash commands yourself with the name of the command
import { Command } from "discord-akairo";
import { Message, User } from "discord.js";
export default class slashCommand extends Command {
public constructor() {
super("slash", {
aliases: ["slooosh", "slash"],
// Args generated by akairo
args: [
{
id: "member",
type: "member"
match: "content",
},
],
//Slash command options you are going to have to register yourself
//You might need to add the types etc yourself for this to be allowed
//This is for yourself to have the options in the command
options: [
{
type: 6,
name: "member",
description: "the member you want to greet",
required: true,
},
],
});
}
exec(message: Message, { member } : { member : GuildMember }) {
message.reply(`Hello ${member}!`)
}
// By default it will use the normal exec method but if you specify execSlash it will run and not the exec
// If you want it to always run execSlash you will have to add the execSlash option to your command handler and it will only use the execSlash and throw a error if you arent using it
execSlash(message: Message, { member } : { member : GuildMember }) {
message.reply(`Hello ${member}!`)
}
}
Note that this example assumes a few things.
- You already have a registered slash command called
avatar
- The registered command has one option named
user
, and- The type is
6
(enum value for user) - Required is
false
- The type is
Message.util.send/reply doesnt work on slash commands to know whats a slash command use message.util.slash, true if true
slash option in commands is just so you can know if a command is slashed for yourself
You can do this all manually using something like an eval command, or just making the http requests to the discord api yourself, or making it automated, but just keep in mind that the library won't register anything for you. Read this or this for how to create/edit/delete slash commands in discord.js.
If you are unaware, an ephemeral response is what causes the "Only you can see this" response with slash commands. You can cause the command to do this with the slashEphemeral
command option. Just add slashEphemeral: true
and it will respond privately.
Warning: fetchReply will not work with ephemeral responses.
This is for slash commands and not normal commands
Yes this fork has tasks!
Example:
//bot.ts
import { TaskHandler } from "discord-akairo"
....
taskHandler: TaskHandler = new TaskHandler(this, {
directory: join(__dirname, "..", "tasks"),
});
....
this.taskHandler.loadAll();
this.taskHandler.startAll();
...
//tasks/task.ts
import { Task } from "discord-akairo";
export default class extends Task {
constructor() {
super("hello", {
delay: 200,
runOnStart: false
});
}
async exec() {
console.log("hello from", this.client.user.username);
}
}
SuperUsers example:
constructor(config: Option) {
super({
ownerID: config.owners,
superUserID: config.superUsers,
});
}
constructor(config: Option) {
super({
ownerID: config.owners,
//Owners arent automatically added as superuser
superUserID: [...config.owners,...config.superUsers],
});
}
Auto defer automatically defers a message aka "BotName is thinking"
commandHandler: CommandHandler = new CommandHandler(this, {
directory: join(__dirname, "..", "Commands"),
prefix: "!",
//To disable it
autoDefer: false
});
Makes a command usable ONLY in NSFW rooms
If a uesr tries to use a command with onlyNsfw: true
in a channel that is not NSFW the CommandHandler will emit the notNsfw
event that can be listened for in order to act in different ways.
Example
export default class NsfwCommand extends Command {
constructor() {
super("nsfw", {
aliases: ["nsfw"],
category: "NSFW 🔞",
onlyNsfw: true,
description: {
content: "Random nsfw example",
usage: "nsfw",
examples: ["nsfw"]
}
});
}
}
- Providers
- mongo
- sequelize
- sqlite
If you want a good database, we recommend using an ORM like sequelize. Databases aren't hard to set up by themselves, and are much more convienent when used without being limited by providers.
For support regarding this fork, you can ping @Tricked in the Akairo discord server #general or preferably join my discord and ask there.