目前,我正试图通过使用不和谐的服务器机器人来开发互动活动,以供课堂使用。我在这方面还是比较新的,但我有基本的要旨,但我还是有一个问题。我已经能够使我的机器人发送消息到特定的通道使用通道is,这是很好的。问题是,这将是杂乱无章的编码,因为目前,我必须重复整个字符串的代码为每个单独的通道。有办法把这些整理成一组整洁的代码吗?目前的情况如下:
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...')它可以工作,但正如您所看到的,它们实际上是相同的,条形码决定了开始时的通道ID。任何帮助清理这将是非常感谢的!
发布于 2021-04-11 10:10:49
您可以将所有目标通道放在一个列表中,并检查通道id是否在所述列表中:
accepted_channels = [insertchannelid1, insertchannelid2]
if message.channel.id in accepted_channels:
if message.content.startswith('hello'):
await message.channel.send('lets begin')
await message.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 message.channel.send('あか! Thank you! That must have to do with this...')https://stackoverflow.com/questions/67043575
复制相似问题