discordjs / commando Goto Github PK
View Code? Open in Web Editor NEWOfficial command framework for discord.js
License: Apache License 2.0
Official command framework for discord.js
License: Apache License 2.0
Instead of having to extend "Command" every time, it would be nice to be able to use it like this:
let c = new Command(bot, {
name: 'add',
group: 'math',
description: 'Performs addition.',
// ....
run: async function(msg, args) {
// ....
}
});
This would allow you to package multiple commands into one class.
When you issue a command that results in the "Invalid Command Usage" Error
It tells you to run !{CommandName} help {CommandName}
rather then !help {CommandName}
I get this error whenever I attempt to register only the default "help" command with commando
/Users/user/Documents/TestBot/node_modules/discord.js-commando/src/commands/argument.js:38
throw new RangeError(`Command argument type "${info.type}" isn't registered.`);
^
RangeError: Command argument type "string" isn't registered.
at new CommandArgument (/Users/user/Documents/TestBot/node_modules/discord.js-commando/src/commands/argument.js:38:10)
at new Command (/Users/user/Documents/TestBot/node_modules/discord.js-commando/src/commands/base.js:198:20)
at new HelpCommand (/Users/user/Documents/TestBot/node_modules/discord.js-commando/src/commands/util/help.js:7:3)
at CommandRegistry.registerCommands (/Users/user/Documents/TestBot/node_modules/discord.js-commando/src/registry.js:114:48)
at CommandRegistry.registerCommand (/Users/user/Documents/TestBot/node_modules/discord.js-commando/src/registry.js:103:15)
at Object.<anonymous> (/Users/user/Documents/TestBot/index.js:10:14)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
Both this:
bot.registry.registerCommand(require('./node_modules/discord.js-commando/src/commands/util/help.js'));
and this give the same error
bot.registry.registerDefaultCommands({
help: true,
prefix: false,
eval_: false,
ping: false,
commandState: false
});
Am I doing this right..? Sorry if this is obvious, I'm new to node.js in general, and couldn't find exact examples on how to use .registerCommand(); anywhere on google.
Thanks in advance.
module.exports = Structures.extend('Guild', Guild => {
^
TypeError: Cannot read property 'extend' of undefined
at Object.<anonymous> (C:\Users\JCM\Git\jazbot-discord\node_modules\discord.js-commando\src\extensions\guild.js:5:28)
Getting this after switching from the npm version to the Github version after realising the npm one is outdated and doesn't have the typings included.
Firstly, I set it manually to zero via: msg.guild.settings.set('test', '0');
let test = msg.guild.settings.get('test');
console.log(test);
msg.guild.settings.set('test', test+1);
After executing the code I checked it again via: msg.guild.settings.get('test');
and it returns like 0111111111, every time the command is executed instead of adding it? Is there any work around or plan to implement this?
I'm wondering if I can change texts like Respond with cancel to cancel the command. The command will automatically be cancelled in 30 seconds.
to something else.
Or even translate strings.
When I type a command in my discord the bot logs this:
(node:11572) DeprecationWarning: EvaluatedPermissions#hasPermission is deprecated, use Permissions#has instead (node:11572) DeprecationWarning: TextChannel#sendMessage: use TextChannel#send instead
I never use HasPermission or sendMessage. The only way I have sent a message has been using message.embed(embed);
Since I discovered this project a few hours ago I wanted to ask before working on the typings and submitting a pull request. I was expecting that a CommondoClient has a property guilds which is of the type Collection<string, GuildExtension>
instead of Collection<string, Guild>
.
I am writing a MongoDB provider and in the setupGuild
method I wanted to access the guild's _commandPrefix
property. Am I missing something?
Edit: Also the additional guild properties like _commandPrefix
, _commandsEnabled
, _groupsEndabled
, and _settings
are private, but you are accessing them directly here: https://github.com/Gawdl3y/discord.js-commando/blob/master/src/providers/sqlite.js#L183
Edit 2: Regardless of the above question there is a typo for this GuildExtension property: private_groupsEndabled: object;
First time using this framework and am porting a simple soundboard bot to ramp up...
One issue i'm facing is defining a command that only accepts a pre-defined list of arguments and having those arguments displayed elegantly when getting help on the command. I see ArgumentType.validate, which could inform the user of valid args on error, but was interested if you saw any value in adding a property to CommandArgumentInfo for this purpose?
Is there a way to call commands from the index.js(mainfile of the bot project)? ( I was not able to get it done via the client's dispatcher for some reason, probably bad method calls as it was giving me an undefined reference)
EvaluatedPermissions#hasPermission is deprecated, use Permissions#has instead
Hello,
I am new to this commando thing so I would like to disable the "Unknown Command" message, is this possible?
Thanks for your time,
Cake
I want to prevent mentioning @botname
(where botname
is the username of the bot) from having the same effect as a prefix and treating whatever comes after it as a command.
Is there any way of doing this?
i tried the beginners guide just to be clear that im not forgotten something
the command is not even loaded even if theres no error with ES6 export/import
my npm run babel:
babel src/ --experimental --source-maps-inline -d build/ && node build/main.js
i've tried to invoke !help all, but the command is not listed
Vip Market
group1
Commands
groups: Lists all command groups.
enable: Enables a command or command group.
disable: Disables a command or command group.
reload: Reloads a command or command group.
load: Loads a new command.
unload: Unloads a command.Utility
help: Displays a list of available commands, or detailed information for a specified command.
prefix: Shows or sets the command prefix.
ping: Checks the bot's ping to the Discord server.
eval: Executes JavaScript code.
import commando from 'discord.js-commando';
export class ReplyCommand extends client.Command {
constructor(client) {
super(client, {
name: 'reply',
group: 'group1',
memberName: 'reply',
description: 'Replies with a Message.',
examples: ['reply']
});
}
async run(msg) {
return msg.say('Hi, I\'m awake!');
}
}
TypeError: Class constructor Command cannot be invoked without 'new'
When compiling using typescript I see the error shown in the title.
I see that the prefix given is internally turned into a regular expression. Would it be possible to give the option to provide a regular expression for a prefix instead? Technically, adding an option for aliases would work, too.
This is more of a question and brainstorm, but it might help someone in a similar situation. More also I am open to recommendations.
I helped crate a CLI app using Yargs. Similar functionality will exist in a Discord bot and the CLI app will be included as a dependency. Should I let the Commando handle passing directly to Yargs. Or should I use Commando to check arguments and call specific functions.
Ultimately it is trying to figure out where to draw the line between the two different sets of mentalities.
Discord.js master logs DeprecationWarning: TextChannel#sendMessage: use TextChannel#send instead
due to commando using the aliases, which are now deprecated.
This error is silently returned if ever there is an undefined object used in the run()
method of a command, which is a really unhelpful error.
Why doesn't it throw the actual error so I know what to look for instead of blindly searching for a typo?
Attempting to reload a command which is not in a folder of the structure ${root}/${group}/${command}.js
causes commando to error internally:
Error in command commands:reload TypeError: Path must be a string. Received null
at assertPath (path.js:7:11)
at Object.join (path.js:468:7)
at CommandRegistry.resolveCommandPath (F:\Github\hobs\node_modules\discord.js-commando\src\registry.js:474:15)
at LinkObject.reload (F:\Github\hobs\node_modules\discord.js-commando\src\commands\base.js:305:35)
at ReloadCommandCommand.run (F:\Github\hobs\node_modules\discord.js-commando\src\commands\commands\reload.js:49:17)
at CommandMessage.run (F:\Github\hobs\node_modules\discord.js-commando\src\commands\message.js:174:33)
I encountered this bug while attempting to reload a command which was a .ts
file rather than a .js
one.
The docs list two properties of CommandInfo, clientPermissions
and userPermissions
, but neither of these seem to be implemented anywhere. Are these coming soon, or are the docs wrong?
This might be a dumb question, but how can I just execute some code inside run
without having to return a value of type Promise<Message | Message[]>
? I just want to use a command and the bot just run it without saying anything in the chat. Returning null doesn't work with Typescript because it's expecting a Promise.
Unrelated, but is there an array type in commando? Want to create a command that will take a list of strings like !choose pizza chinese indian
and the arg parser will pass ["pizza", "chinese", "indian"] to the run method.
C:\Users\Administrator\Desktop\Discord botlar\Bot Rewrite\node_modules\discord.js-commando\src\commands\message.js:259
if(this.message.guild && !this.message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) {
^
TypeError: this.message.channel.permissionsFor(...).hasPermission is not a function
at CommandMessage.respond (C:\Users\Administrator\Desktop\Discord botlar\Bot Rewrite\node_modules\discord.js-commando\src\commands\message.js:259:84)
at CommandMessage.embed (C:\Users\Administrator\Desktop\Discord botlar\Bot Rewrite\node_modules\discord.js-commando\src\commands\message.js:393:15)
at gotFormats (C:\Users\Administrator\Desktop\Discord botlar\Bot Rewrite\node_modules\ytdl-core\lib\info.js:225:7)
at C:\Users\Administrator\Desktop\Discord botlar\Bot Rewrite\node_modules\ytdl-core\lib\info.js:211:7
at IncomingMessage. (C:\Users\Administrator\Desktop\Discord botlar\Bot Rewrite\node_modules\miniget\lib\index.js:75:11)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Made a command group, realised it was a flawed concept, and scrapped the idea. I deleted the line ["swear_jar","description"],
from the bot.registry.registerGroups()
function in my main bot file, and deleted the folder /commands/swear_jar/
, and on saving the file and running the bot again, I recieved the following error:
plx for the helping ty
Mundane
Not sure about this one because this is all the errors it gives, am I right in assuming this hasn't been updated to match the latest version of discord.js? Thanks.
(node:15260) DeprecationWarning: EvaluatedPermissions#hasPermission is deprecated, use Permissions#has instead
(node:15260) DeprecationWarning: TextChannel#sendMessage: use TextChannel#send instead
In the README it says that Node 8.0.0 or newer is required, but on the linked documentation pages it says that Node 7.6.0 or newer is required. Which one is correct?
When giving the exact name of a channel as a channel type argument, if there is another channel that contains the formerly mentioned channel's name, the other channel is chosen.
Example:
Test
A Test Channel
!mycommand Test
A Test Channel is automatically selected, instead of Test.
It seems like the guild command settings are not working properly. When I restart the bot, my guild command settings are reset (they are still in the database.sqlite3 file though). The prefix guild setting is working fine however. Below are issues I have (and one WAI):
Anything I need to fix to get this to work?
If a user changes the prefix to <
While they will still be able to use <prefix
to bring up the prefix command, they can no longer use @BotMention prefix
this will now trigger a unrecognized command.
as 1Computer said in discord
because their regex matches < then @id> prefix
I received this error for the first time today and I'm not sure what changed to cause this.
The stack trace is
at CommandMessage.reply (/Users/me/Documents/DiscordBot/node_modules/discord.js-commando/src/commands/message.js:351:15)
at Argument.obtainInfinite (/Users/me/Documents/DiscordBot/node_modules/discord.js-commando/src/commands/argument.js:245:29)
at Argument.obtain (/Users/me/Documents/DiscordBot/node_modules/discord.js-commando/src/commands/argument.js:130:33)
at ArgumentCollector.obtain (/Users/me/Documents/DiscordBot/node_modules/discord.js-commando/src/commands/collector.js:74:30)
at CommandMessage.run (/Users/me/Documents/DiscordBot/node_modules/discord.js-commando/src/commands/message.js:160:52)
at CommandDispatcher.handleMessage (/Users/me/Documents/DiscordBot/node_modules/discord.js-commando/src/dispatcher.js:127:32)
at CommandoClient.on.message (/Users/me/Documents/DiscordBot/node_modules/discord.js-commando/src/client.js:68:51)
at emitOne (events.js:115:13)
at CommandoClient.emit (events.js:210:7)
It would be really great if inhibitor function and/or hasPermission()
function would be able to deal with asynchronous code inside. It seems from the source point of view rewritting hasPermission()
to deal with async would take a bit of work and might be prone to bugs (hell, if no one wants to do it, I can) so I propose an alternative function HasPermissionAsync()
or whatever you guys like more. It would require just additional, perhaps, redundant if
check in discord.js-commando/src/commands/message.js #134
if(!this.command.hasPermission(this)) {
this.client.emit('commandBlocked', this, 'permission');
return this.reply(`You do not have permission to use the \`${this.command.name}\` command.`);
}
There could also be an additional check, let's say..
if(! await this.command.hasPermissionAsync(this)) {
this.client.emit('commandBlocked', this, 'permission');
return this.reply(`You do not have permission to use the \`${this.command.name}\` command.`);
}
This doesn't seem to cause any issues since run() method is async
itself. It might be redundant, but gives flexibility for users who want async
code to be run in hasPermission()
and those who don't. The same goes for inhibitor functions, to be honest, I can't get the sense why they are not async to begin with.
Now, pardon my walls of text, the reason I am proposing this is that I am developing myself a commando based bot and my application is quite restrictive in terms of who can do what and when. Meaning there has to be a permission / role check for every command user requests. All that translates to various services calling to database and retrieving relevant information and forming a response whether that user can, at this point of time, use desired command. Back to the point, all those services that connect to database are asynchronous, because database calls by nature are like that in Node and that makes things complicated when commando
does not handle async code. This issue I am having could've been solved either by inhibitor and/or hasPermission method call if they handled async code.
I could, of course, just do redundant and nightmare to maintain checks in every command I develop, but honestly, the thought alone, makes me regret to porting my code to commando
. My code previously was mostly plain discord.js with npm clapp
package integration. Good parts, it was very flexible, but became a nightmare to maintain in the long run due to lack of solid structure. Commando has that, but lacks flexibility part. I am hoping for a decent middle ground between the two.
A lot of people like to use cleverbot with their bots, and the best way to do that is by having the bot react when it is mentioned, so a way to make executing commands on bot mention optional would be good.
Hello,
Anybody have an idea about that error?
TypeError: this.commands.filterArray is not a function
https://discord.js.org/#/docs/commando/master/class/CommandMessage?scrollTo=say says what it does, but should there not also be written that it is a shortcut for message.channel.sendMessage()
?
Currently when having the nsfw option enabled for a CommandMessage you can also not use any of such commands in DMs. I think it is safe to assume that if someone is talking to a bot in a private message they are full and well aware of what they are doing to begin with and therefore I think that even with nsfw enabled, these commands should be usable in DMs.
Currently returns:
For obvious reasons not showing what I want it to return.
I have no clue how to do this can someone help me? I cant even find stuff on google about it
While SQLite is great for getting started, host providers like Heroku don't give you a file system that remains constant.
Unless there's a reason not to, I'd like to add a new Provider that uses MongoDB
I keep getting this error when the bot starts. There is no fetchUser function!
PS C:\Users\Ali\Desktop\Coding\Discord\MasterAJ> node bot.js
Uncaught Promise Error:
TypeError: this.fetchUser is not a function
at CommandoClient.once (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\discord.js-commando\src\client.js:78:12)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at CommandoClient.emit (events.js:207:7)
at WebSocketConnection.triggerReady (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:105:17)
at WebSocketConnection.checkIfReady (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:121:61)
at GuildCreateHandler.handle (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\discord.js\src\client\websocket\packets\handlers\GuildCreate.js:14:31)
at WebSocketPacketManager.handle (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:290:35)
at WebSocketConnection.onMessage (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:252:22)
at WebSocket.onMessage (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\ws\lib\EventTarget.js:99:16)
at emitOne (events.js:115:13)
at WebSocket.emit (events.js:210:7)
at Receiver._receiver.onmessage (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\ws\lib\WebSocket.js:143:47)
at Receiver.dataMessage (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\ws\lib\Receiver.js:380:14)
at Receiver.getData (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\ws\lib\Receiver.js:330:12)
at Receiver.startLoop (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\ws\lib\Receiver.js:165:16)
at Receiver.add (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\ws\lib\Receiver.js:139:10)
at TLSSocket._ultron.on (C:\Users\Ali\Desktop\Coding\Discord\MasterAJ\node_modules\ws\lib\WebSocket.js:139:22)
at emitOne (events.js:115:13)
at TLSSocket.emit (events.js:210:7)
at addChunk (_stream_readable.js:252:12)
at readableAddChunk (_stream_readable.js:239:11)
at TLSSocket.Readable.push (_stream_readable.js:197:10)
at TLSWrap.onread (net.js:589:20)
when I try to put multiple bot owners, it doesn't let me
const client = new commando.Client({ owner: [ '186082941082796032', //crowlKats '99170206101807104', //Crowes '208499873341898753' //ClassyGamer ] });
(node:201986) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): DiscordAPIError: Invalid Form Body user_id: Value "186082941082796032,99170206101807104,208499873341898753" is not snowflake.
Something that I have seen the need of in some of my bots is deleting the messages that initiated a command. An option that allows for the message the initiated a command to be deleted. This includes the helper messages for arguments. I can delete the very first message that the user sends, but if any helper messages are sent by the bot asking for arguments, there is no way (that I know of) that you can delete them and the responses from the user.
Hello!
Just got into creating my own discord bot and i'm hitting an error when I have a command with no arguments.
...
args: []
...
I'm getting this:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'infinite' of undefined
At the moment it is not possible to specify an individual argument by a value when sending a command to a bot. It would be useful to add a command that permits you to specify a command by setting a property called argPrefix
. The default for this property could be the value set to the key
property.
Take a command called foo
. The foo
command has two arguments: bar
and round
. bar
and round
both have a default value set to false
. If you run foo
it checks if one of the values is marked as true
and if it is, it returns the argument(s) that were set to true
.
Now say we only want to specify true
for round
and not want to have to specify false
for bar
in the command send to the bot. At the moment this is not possible with Commando.
I propose therefore adding a argPrefix
property that, if specified, allows you to specify a specific command with the syntax (moving back to my example): $foo round=true
for example.
Good question. My example foo
command may only have had two arguments, but what if you for example have a command with fifteen arguments? In that case it can save a potential user a lot more time if for example they could only specify a single argument when the other arguments are provided by the default set in the bot itself.
The reasoning for splitting this configuration option from the key
property is that the variable which is set in type
might not be entirely useful to type out for a user to help them to identify the command.
Solved
I am still fairly new to javascript and it's basics, but i still wanted to try my hand at building a discord bot, when i tried to make a simple ban command i ran into an issue.
See, every time i try to run it i run into some errors like these:
(node:1104) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: B ad Request (node:1104) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise r ejections that are not handled will terminate the Node.js process with a non-zero exit code. (node:1104) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeErro r: Cannot read property 'username' of undefined
This is my code:
const discord = require('discord.js');
const commando = require('discord.js-commando');
class BanCommand extends commando.Command {
constructor(client) {
super(client, {
name: 'ban',
group: 'random',
memberName: 'ban',
description: 'bans a user',
args: [
{
key: 'member',
label: 'member',
prompt: 'What user would you like to ban?',
type: 'member'
}
]
});
}
async run(message, args) {
msg.channel.permissionsFor(client.member).isOwner(user);
msg.channel.guild.banMember(member.id, deleteDays);
}
}
module.exports = BanCommand;
thx for helping, i know this is dumb, but please help anyways, since i am a noob.
Let's say I have a command like /events
I want to create /events add
, /events remove
and so on.
Code
const commando = require('discord.js-commando');
var cleverbot = require("cleverbot.io"),
class TalkCommand extends commando.Command {
constructor(client) {
super(client, {
name: 'talk',
group: 'general',
memberName: 'talk',
description: "Shows information about Mitro",
aliases: ['t']
});
}
async run(message, args) {
cleverb = new cleverbot("private", "private");
cleverb.setNick("Nitro");
bot.create(function (err, session) {
bot.ask("Just a small town girl", function (err, response) {
console.log(response); // Will likely be: "Living in a lonely world"
});
});
}
}
module.exports = TalkCommand;
Error:
(node:5396) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'map' of null
(node:5396) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Does anyone have any ideas?
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.