How to make a discord bot edits its code? - python

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?

Related

Discord.py mention application command

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.

create a constant fuction in telebot

I am creating a telegram bot using telebot and i want to make a function that will work constantly regardless of whether a person writes something to bot or not. How can i make it? In this function i want to place a code that will check the time everytime.
I've tried to add a "constant" fuction to all the others, but thats not what i need.
Should i make it in decoraters like
`#bot.message_handler()`

Is there a way for me to disable a command for a certain role in discord.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.

what does the "ctx" really doing discord.py

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.

discord.py - Obtaining channel object from mentioned channel

I am looking for a way of which I can obtain the name and ID of the channel, from when someone sends a command followed by a channel mention, such as --command #CHANNEL. I have seen this done on other public bots, but I have, as of yet, found no way to reproduce this. This is probably a stupid question, but I would highly appreciate any help or thoughts you could put towards this.
Thanks in advance,
Nat.
You would need to make sure a channel is an expected parameter in the command definition. This code creates a command for the bot called 'test' that expects an object of the discord.Channel class to be passed as a parameter:
bot.command()
async def test(channel: discord.Channel):
You could then get the name and id using channel.name and channel.id, respectively.

Categories