Code for a user specify channel for bot to post in. (Discord.py)

Viewed 147

I am making a bot, that auto posts memes from reddit, to a specified channel. The only problem is, I have no idea on how to make a command that will let the user customize what channel they want that task to be posted to and get the id.

I tried

@client.command()
async def memer config(ctx):
    await client.send('Where do you want the automemer to post?')

This obviously did not work because I had no clue how to get the message that the person who executed the command, and to check if it was a valid channel mention.

1 Answers

The way I would do it is like this:

  1. Person uses command memer config
  2. Bot replies with set current channel as meme channel
  3. Your script savze the channel id (ctx.channel.id) somewhere (in an SQL database would be ideal)
  4. Retrieve the channel id associated with the user's id when needed, channel = client.get_channel(channel_id)
  5. Post them memes using await channel.send("them memes")

Hope that helped

Related