在 python 中编程一个 Discord 机器人 - 如何让机器人从一组图像中发送随机图像?

时间:2021-01-12 03:18:47

标签: python discord.py

我想让我的不和谐机器人在有人说“狗”时从一组图像中随机发送一个图像。这是我所拥有的:

@client.event
async def on_message(message):
  if message.content.startswith('dog'):
    await message.channel.send(file=discord.File(random.choice('dog1.JPG', 'dog2.JPG', 'dog3.JPG')))

它似乎不起作用,有什么想法吗?

1 个答案:

答案 0 :(得分:1)

random.choice 将一系列可供选择的项目作为参数,而不是单个项目。你需要做random.choice(('dog1.JPG', 'dog2.JPG', 'dog3.JPG'))

相关问题