'Discord bot: The base SlashCommand cannot be instantiated
On my computer it works fine, but when I try to host it on Heroku it gives this error
/app/node_modules/slash-create/lib/command.js:21 throw new Error('The base SlashCommand cannot be instantiated.'); ^
Error: The base SlashCommand cannot be instantiated. at new SlashCommand (/app/node_modules/slash-create/lib/command.js:21:19) at new module.exports (/app/commands/back.js:5:9) at SlashCreator.registerCommand (/app/node_modules/slash-create/lib/creator.js:64:23) at SlashCreator.registerCommands (/app/node_modules/slash-create/lib/creator.js:105:18) at SlashCreator.registerCommandsIn (/app/node_modules/slash-create/lib/creator.js:132:21) at Object. (/app/index.js:39:6) at Module._compile (internal/modules/cjs/loader.js:1072:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) at Module.load (internal/modules/cjs/loader.js:937:32) at Function.Module._load (internal/modules/cjs/loader.js:778:12)
Solution 1:[1]
You are trying to register the base SlashCommand class as a command. You have to extend off of the class and add options to your command.
const { SlashCommand, CommandOptionType } = require('slash-create');
module.exports = class HelloCommand extends SlashCommand {
constructor(creator) {
super(creator, {
name: 'hello',
description: 'Says hello to you.',
options: [{
type: CommandOptionType.STRING,
name: 'food',
description: 'What food do you like?'
}]
});
this.filePath = __filename;
}
async run(ctx) {
return ctx.options.food ? `You like ${ctx.options.food}? Nice!` : `Hello, ${ctx.user.username}!`;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Snazzah |