I am trying to make a help menu for my discord bot, and would like to make it similar to MEE6's, where it mentions application commands.
But rather than typing myself each command by hand, I would like to automate the process, so that if I add a new command it automatically adds it to the list.
I can easily obtain the commands with tree.get_commands(), but I don't know how to mention them: I found that typing "</command_name:command_id>" works, but I find nowhere on the docs how to get the id of an application command. Currently the only way I know of is with Discord Developer Mode.
Is there something I'm missing?
For anyone who ecounters this problem: I was not using the correct command.
I wanted to get type discord.AppCommand, but tree.get_commands() returns discord.Command.
So you get all the Application Commands using await tree.fetch_commands(), and those actually have the id that can be used to mention the command.
Related
I have a discord bot (With Py-cord), and I want to have a command (Only I can use it) that makes a specific command not available to use, for example:
/stop ban
/start mute
So my idea is that the command will edit the guild_ids property and make the command only available for me to use, for example:
before:
#slash_command()
after:
#slash_command(guild_ids=[MY_SERVER_ID])
So my question: is it possible to do? and how to? and is there a better way to do it?
For example, let's say I wanted to set a variable in powershell (or command line), and then get that variable later using something like subprocess.check_output("echo $var", shell=True) (this isn't something I need to do, just an example). Or, lets say I wanted to have a user 'cd' to a directory, and be able to run commands from that directory. I would be able to have some python variable that saves the current directory, and always run "cd {dir};{command}", but that would be inefficient, and still wouldn't work for every situation, I would need to add some special bit of code for every possible situation where a user could want to run a command, then run another command which depends on the first command.
Sorry if I phrased this question badly, let me know if I should clarify. TIA!
Ok, after some searching, I found a way to do this. Using a module called pexpect, MarkBaggett on GitHub has made a simple way to do this: pxpowershell. here's an example:
ps = pxpowershell()
ps.start_process()
ps.run("$x = 10")
print(ps.run("echo $x"))
ps.stop_process()
The only small problems are that 1. colors don't work, and 2. you need to decode() and strip() the output, though you can just add that into the pxpowershell.py.
Exactly what the title says. I have someone abusing a certain command that I would like to restrict a role that they have from using said command. Is there a ay to do that? and if so, can someone please write the example code?
under the decorator for your command (#bot.command()) use #commands.has_role("roleName") to limit the command to only that role.
Im programming a discord bot in Python
and every tutorial on Youtube telling me that i have to use the 'ctx' when im making a command,
but none of those Youtubers explaining what this is doing, so pls can someone answer me?
As explained in the docs:
A command must always have at least one parameter, ctx, which is the Context as the first one.
Now, what is Context? Again, the docs:
Represents the context in which a command is being invoked under.
This class contains a lot of meta data to help you understand more about the invocation context. This class is not created manually and is instead passed around to commands as the first parameter.
I'm trying to get results of db.stats() mongo shell command in my python code (for monitoring purposes).
But unlike for example serverStatus I can't do db.command('stats'). I was not able to find any API equivalent in mongodb docs. I've also tried variations with db.$cmd but none of that worked.
So,
Small question: how can I get results of db.stats() (number of connections/objects, size of data & indexes, etc) in my python code?
Bigger question: can anyone explain why some of shell commands are easily accessible from API, while others are not? It's very annoying: some admin-related tools are accessible via db.$cmd.sys, some via db.command, some via ...? Is there some standard or explanation of this situation?
PS: mongodb 2.0.2, pymongo 2.1.0, python 2.7
The Javascript shell's stats command helper actually invokes a command named dbstats, which you can run from PyMongo using the Database.command method. The easiest way to find out what command a shell helper will run is to invoke the shell helper without parentheses -- this will print out the Javascript code it runs:
> db.stats
function (scale) {
return this.runCommand({dbstats:1, scale:scale});
}
As for why some commands have helpers and others do not, it's largely a question of preference, time, and perceived frequency of use by the driver authors. You can run any command by name with Database.command, which is just a convenience wrapper around db.$cmd.find_one. You can find a full list of commands at List of Database Commands. You can also submit a patch against PyMongo to add a helper method for commands you find that you need to invoke frequently but aren't supported by PyMongo yet.