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.
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?
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.
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 have designed an irc bot using python.
Here is the code for that bot:-
https://github.com/sheeshmohsin/theb0t/blob/sheesh/ekan0ra.py
It is working fine but it is joining in one channel and i have to made it to join in more than one channel. Please give me ideas or the way i can do it.
You can use the JOIN command, either multiple times for each channel, or as documented in RFC 1459:
self.sendLine("JOIN #channel1,#channel2,#channel3")
Optionally you may include keys:
self.sendLine("JOIN #channel1,#channel2,#channel3 key1,,key3#")
This example demonstrates joining three channels where the second channel has no key.