discord-commander.js v1.3.6
discord-commander.js
discord-commander.js est une librairie permettant de géré les messages commandes et les slash commandes.
Procédure d'installation npm i discord-commander.js
Documentation :
Classes
CommandManager
Constructor :
new CommandManager(client, ownerIds, onCommand);
Paramètre | Type | Optionnel |
---|---|---|
client | Client | non |
ownerIds | Array< Snowflake > | non |
onCommand | CommandMangerOnCommand | oui |
Methodes :
- registerCommand(command)
Paramètre | Type | Optionnel |
---|---|---|
command | Command | Oui |
retourne CommandManager
- registerCommands(commands)
Paramètre | Type | Optionnel |
---|---|---|
commands | Array< Command > | oui |
retourne CommandManager
Dispatcher
Constructor :
new Dispatcher(options);
Paramètre | Type | Optionnel |
---|---|---|
options.prefix | string | non |
options.responseOnMention | boolean | non |
options.commandManager | CommandManager | non |
options.deleteCommand | boolean | non |
options.enableResponseByMessageForSlashCommand | boolean | non |
options.parseArgs | CommandParseArgs | oui |
options.commandOptions | Object | non |
Methodes :
- onMessage(message)
Paramètre | Type | Optionnel |
---|---|---|
message | Message | non |
retourne void
- onCommandInteraction(interaction)
Paramètre | Type | Optionnel |
---|---|---|
interaction | CommandInteraction | non |
retourne void
CommandData
Constructor :
new CommandData(enableSlashCommand, guildIds);
Paramètre | Type | Optionnel |
---|---|---|
enableSlashCommand | CommandDataEnableSlashCommand | oui |
guildIds | Array< Snowflake > | oui |
Methodes :
- setName(name)
Paramètre | Type | Optionnel |
---|---|---|
name | string | non |
retourne CommandData
- setDescription(description)
Paramètre | Type | Optionnel |
---|---|---|
description | string | non |
retourne CommandData
- setOptions(options)
Paramètre | Type | Optionnel |
---|---|---|
options | Array< CommandOptionsData > | non |
retourne CommandData
- addOption(option)
Paramètre | Type | Optionnel |
---|---|---|
option | CommandOptionsData | non |
retourne CommandData
- setDefaultPermission(defaultPermission)
Paramètre | Type | Optionnel |
---|---|---|
defaultPermission | Boolean | non |
retourne CommandData
- setAliases(aliases)
Paramètre | Type | Optionnel |
---|---|---|
aliases | Array< string > | non |
retourne CommandData
- addAlias(alias)
Paramètre | Type | Optionnel |
---|---|---|
alias | string | non |
retourne CommandData
- setGroup(group)
Paramètre | Type | Optionnel |
---|---|---|
group | string | non |
retourne CommandData
- setHidden(hidden)
Paramètre | Type | Optionnel |
---|---|---|
hidden | string | non |
retourne CommandData
- setExamples(examples)
Paramètre | Type | Optionnel |
---|---|---|
examples | Array< string > | non |
retourne CommandData
- addExample(example)
Paramètre | Type | Optionnel |
---|---|---|
example | string | non |
retourne CommandData
- setClientPermissions(clientPermissions)
Paramètre | Type | Optionnel |
---|---|---|
clientPermissions | Array< PermissionResolvable > | non |
retourne CommandData
- addClientPermission(clientPermission)
Paramètre | Type | Optionnel |
---|---|---|
clientPermission | PermissionResolvable | non |
retourne CommandData
- setAuthorPermissions(authorPermissions)
Paramètre | Type | Optionnel |
---|---|---|
authorPermissions | Array< PermissionResolvable > | non |
retourne CommandData
- addAuthorPermission(authorPermission)
Paramètre | Type | Optionnel |
---|---|---|
authorPermission | PermissionResolvable | non |
retourne CommandData
- setThrottling(usages, duration)
Paramètre | Type | Optionnel |
---|---|---|
usages | number | non |
duration | number | non |
retourne CommandData
- setGuildOnly(guildOnly)
Paramètre | Type | Optionnel |
---|---|---|
guildOnly | boolean | non |
retourne CommandData
- setOwnerOnly(guild, bot)
Paramètre | Type | Optionnel |
---|---|---|
guild | boolean | non |
bot | boolean | non |
retourne CommandData
- setUnknown(unknown)
Paramètre | Type | Optionnel |
---|---|---|
unknown | boolean | non |
retourne CommandData
- get(property)
Paramètre | Type | Optionnel |
---|---|---|
property | string | non |
retourne string
CommandOptionsData
Constructor :
new CommandOptionsData();
Methodes :
- setType(type)
Paramètre | Type | Optionnel |
---|---|---|
type | ApplicationCommandOptionType | non |
retourne CommandOptionsData
- setName(name)
Paramètre | Type | Optionnel |
---|---|---|
name | string | non |
retourne CommandOptionsData
- setDescription(description)
Paramètre | Type | Optionnel |
---|---|---|
description | string | non |
retourne CommandOptionsData
- setRequired(required)
Paramètre | Type | Optionnel |
---|---|---|
required | boolean | non |
retourne CommandOptionsData
- setChoices(choices)
Paramètre | Type | Optionnel |
---|---|---|
choices | Array< ApplicationCommandOptionChoice > | non |
retourne CommandOptionsData
- addChoice(name, value)
Paramètre | Type | Optionnel |
---|---|---|
name | string | non |
value | string | number | non |
retourne CommandOptionsData
- setOptions(options)
Paramètre | Type | Optionnel |
---|---|---|
options | Array< CommandOptionsData > | non |
retourne CommandOptionsData
- addOption(option)
Paramètre | Type | Optionnel |
---|---|---|
option | CommandOptionsData | non |
retourne CommandOptionsData
CommandContext
Propriété :
- args (type : CommandArgs)
Methodes :
- get(property)
Paramètre | Type | Optionnel |
---|---|---|
property | string | non |
retourne string
- send(options)
Paramètre | Type | Optionnel |
---|---|---|
property | MessageOptions | InteractionReplyOptions | non |
retourne Promise< Message | void >
- reply(options)
Paramètre | Type | Optionnel |
---|---|---|
property | ReplyMessageOptions | InteractionReplyOptions | non |
retourne Promise< Message | void >
- getContextBase()
retourne CommandInteraction | Message
CommandArgs
Methodes :
- getSubCommandGroup()
retourne string | null
- getSubCommand()
retourne string | null
- get(name)
Paramètre | Type | Optionnel |
---|---|---|
name | string | non |
retourne CommandArg
Command
Methodes :
- getData()
retourne CommandData
Types
CommandMangerOnCommand
type : function
Example : function (command, context) {}
Paramètre | Type | Optionnel |
---|---|---|
command | Command | non |
context | CommandContext | non |
retourne void
CommandParseArgs
type : function
Example : function (commandData, guild, args, setArg) {}
Paramètre | Type | Optionnel |
---|---|---|
commandData | CommandData | non |
guild | Guild | undefined | non |
args | Array< string > | non |
setArg | (name: string, data: CommandArg) => void | non |
retourne void
CommandDataEnableSlashCommand
type : string | null
Value :
- GLOBAL
- GUILD
- null
CommandArg
type: Object
Key | Type | Optionnel |
---|---|---|
name | string | non |
value | string | number | boolean | undefined | non |
user | User | null | non |
member | GuildMember | null | non |
channel | GuildChannel | ThreadChannel | null | non |
role | Role | null | non |
Exemple de code
const Discord = require('discord.js');
const Handler = require('discord-commander.js');
class UserInfo extends Handler.Command {
constructor() {
const user = (new Handler.CommandOptionsData())
.setType('USER')
.setName('user')
.setDescription('user description')
.setRequired(true);
const command = (new Handler.CommandData('GUILD'))
.setName('user-info')
.setDescription('user-info description')
.addOption(user);
super(command);
}
execute(context, options) {
const {user} = context.args.get('user');
context.reply({
content: `User: ${user.id} | group: ${context.args.getSubCommandGroup()} | sub: ${context.args.getSubCommand()}`
}).catch(console.error);
}
onError(error, context) {}
slashCommandPermissions(commandId, permissionsManager) {}
}
const client = new Discord.Client({intents: Object.values(Discord.Intents.FLAGS).reduce((acc, p) => acc | p, 0)});
const manager = new Handler.CommandManager(client, ['YOUR ID']).registerCommands([new UserInfo()]);
const dispatcher = new Handler.Dispatcher({
prefix: '!',
responseOnMention: true,
commandManager: manager,
deleteCommand: true,
enableResponseByMessageForSlashCommand: true,
commandOptions: {},
});
client.on('ready', () => console.log('ready'));
client.on('interactionCreate', (interaction) => {
if (interaction.isCommand()) client.emit('commandInteractionCreate', interaction);
if (interaction.isButton()) client.emit('buttonInteractionCreate', interaction);
if (interaction.isSelectMenu()) client.emit('selectMenuInteractionCreate', interaction);
});
client.on('messageCreate', message => dispatcher.onMessage(message));
client.on('messageUpdate', (oldMessage, message) => {
if (message instanceof Discord.Message) dispatcher.onMessage(message);
});
client.on('commandInteractionCreate', interaction => dispatcher.onCommandInteraction(interaction));
client.login('YOUR TOKEN').catch(console.error);