Nat L
Nat L

Reputation: 7

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.

Upvotes: 0

Views: 2550

Answers (1)

hopethatsacleanwet
hopethatsacleanwet

Reputation: 418

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.

Upvotes: 1

Related Questions