Elliot Smith
Elliot Smith

Reputation: 13

Get the ID of a discord channel with a bot with discord.py

I am writing a bot that needs to send a message in a channel where the user has activated it. I can't seem to find out how to get the channel ID from a message.

@bot.command(name="start", description="Starts for a channel")
async def start(ctx):
     await ctx.send("Started")
     #Get channel ID here and assign it to the var channel


@tasks.loop(seconds=2)
async def message()
     channel = bot.get_channel(channel)
     await channel.send("Message")

Upvotes: 1

Views: 774

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

To get channel ID use ctx.channel.id. However you can already pass the channel into the message loop.

@bot.command(name="start", description="Starts for a channel")
async def start(ctx):
     await ctx.send("Started")
     message.start(ctx.channel)


@tasks.loop(seconds=2)
async def message(channel):
     await channel.send("Message")

Upvotes: 1

Related Questions