Search code examples
pythondiscorddiscord.py

Can I use a variable to store a channel ID to be called later? Discord.py


I am trying to make a bot that will take a message from one channel and send it to another. Currently this is my code

  linkchannel = message.channel.topic
  print(linkchannel)
  await asyncio.sleep(1)
  channel = client.get_channel(linkchannel)
  await channel.send('{} : {}'.format(message.author.name, message.content))
  await client.process_commands(message)

The channel id is stored in the channel topic, but the variable is not working as the argument for getting the channel. If I put the channel ID in it works just fine but for this I really need it to be controlled by a variable. Anyone know how to use the variable to get the number or make it possible to get the channel through the variable?


Solution

  • I figured it out, all it was is that I had to specify the variable should be an Int. Declaring the variable needed to be

    linkchannel = int(message.channel.topic)