I am trying to make a discord bot which will send the channel id in response to a command. For example, if I type the command '$channel' this bot will return the channel id of the channel where I send the command.
I have the following so far (command prefix already set to '$'):
'''
client.command(name = 'channel')
async def channel(ctx):
await ctx.send(#not sure how to return channel id)
'''
It feels like there's a simple solution to this but I have not been able to figure it out.
CodePudding user response:
It's simple:
@client.command(name = 'channel')
async def channel(ctx):
await ctx.send(ctx.channel.id)
ctx
stores many information - the user who used the command, server, channel, etc. (check all). After getting the channel
object you can get the id
.