[英]Programming a Discord bot in python- How do make the bot send a random image from a group of images?
I want to make my discord bot send a random image from a group of images whenever someone says "dog".每当有人说“狗”时,我想让我的 discord 机器人从一组图像中发送一个随机图像。 Here's what I have:
这是我所拥有的:
@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')))
It doesn't seem to be working, any ideas?它似乎不起作用,有什么想法吗?
random.choice
takes a sequence of items to choose from as an argument, not the individual items. random.choice
将一系列可供选择的项目作为参数,而不是单个项目。 You need to do random.choice(('dog1.JPG', 'dog2.JPG', 'dog3.JPG'))
你需要做
random.choice(('dog1.JPG', 'dog2.JPG', 'dog3.JPG'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.