I'm currently trying to develop interactive activities through use of Discord server bots for classroom purposes. I am fairly new at this but have got the basic gist of things, I do have a question though. I have been able to make my bot send messages to specific channels using the channel IDs which is great. The problem is that this is going to be messy in coding as at the moment I have to duplicate the entire string of code for each individual channel. Is there a way to tidy this up into one neat set of code? Currently it looks like this:
if (message.channel.id == insertchannelid1):
channel = client.get_channel(insertchannelid1)
if message.content.startswith('hello'):
await channel.send('lets begin')
await channel.send('I cant seem to see the word hidden here, can you use your flashlight to help me?')
await message.channel.send(file=discord.File('Spotlight_demo.exe'))
if message.content.startswith('あか'):
await channel.send('あか! Thank you! That must have to do with this...')
if (message.channel.id == insertchannelid2):
channel = client.get_channel(insertchannelid2)
if message.content.startswith('hello'):
await channel.send('lets begin')
await channel.send('I cant seem to see the word hidden here, can you use your flashlight to help me?')
await message.channel.send(file=discord.File('Spotlight_demo.exe'))
if message.content.startswith('あか'):
await channel.send('あか! Thank you! That must have to do with this...')
It works but as you can see they are literally identical bar the code which determines the channel ID at the beginning. Any help tidying this up would be much appreciated!