ming-suhi / da-slash Goto Github PK
View Code? Open in Web Editor NEWCreating and managing Discord Slash Commands made simple
License: MIT License
Creating and managing Discord Slash Commands made simple
License: MIT License
Describe the bug
When using the categories option it requires command files from da-slash's node_modules directory, instead of the location the module is required at. IE. Commands are in './commands/folders/' but it's looking for them in './node_modules/da-slash/src/commands/folders/'
// ./bot.js
config = {
commands: {
directory: './commands',
subcategories: 'true'
}
}
// ./node_modules/da-slash/src/client.js
9 | async commands() {
21 | let command = require(`${dir}/${folder}/${file}`);
37 | async findCommand(command_name) {
49 | let command = require(`${dir}/${subfolderRef}/${file}`);
The error being produced
UnhandledPromiseRejectionWarning: Error: Cannot find module './commands/subcategory/command.js'
Expected behavior
Expected to find existing module at specified location.
Additional context
Adding require.main.require();
to line 21 and 49 in client.js fixed the issue for me
While da-slash does provide a delete function, it's only setup for commands it created and that still exists.
So if I delete a command's file, I can no longer call it up and delete it, I'd have to recreate the command with the same name, then delete it.
Here's a deleteCommands function that could be added to client.js, allowing you to delete all commands initialized by the bot, either globally or per guild via await slash.deleteCommands(guild_ids, del_global)
.
guild_ids
being an array of guild ids.
del_global
being a boolean to delete global commands or not.
Function
async deleteCommands(guild_ids = false, del_global = false) {
let deletedCommands = new Array();
if (guild_ids) {
let postedGuildCommands = new Array();
for (let guild_id of guild_ids) {
const guildCommands = await this.client.api.applications(this.client.user.id).guilds(guild_id).commands.get();
for (let i = 0; i < guildCommands.length; i++) {
this.client.api.applications(this.client.user.id).guilds(guild_id).commands(guildCommands[i].id).delete();
}
postedGuildCommands.push({ guild: guild_id, commands: guildCommands });
}
deletedCommands.push({ guilds: postedGuildCommands });
}
if (del_global) {
const postedGlobalCommands = await this.client.api.applications(this.client.user.id).commands.get();
for (let i = 0; i < postedGlobalCommands.length; i++) {
this.client.api.applications(this.client.user.id).commands(postedGlobalCommands[i].id).delete();
}
deletedCommands.push({ global: postedGlobalCommands });
}
return deletedCommands;
}
Usage
client.on('ready', async () => {
await slash.deleteCommands(['613425648685547541','197038439483310086'], true);
slash.postCommands();
});
Originally posted by @fasko-web in #8
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.