简体   繁体   English

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

[英]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.

相关问题 在 Python 中编程 Discord 机器人 - 如何让机器人从 subreddit 发送随机文本组? - Programming a Discord bot in Python- How do I make the bot send a random group of text from a subreddit? 在 Discord 中编程机器人 - 如何让机器人从 subreddit 发送随机图像? - Programming a bot in Discord- How do I make the bot send a random image from a subreddit? 在 Python 中编程 Discord 机器人 - 如何让机器人重复图像? - Programming a Discord bot in Python- How do I make the bot repeat an image? 在 Python 中编程 Discord 机器人 - 如何使嵌入具有随机颜色? - Programming a Discord bot in Python- How do I make an embed have a random color? 用 Python 编写 Discord 机器人 - 如何让它每天在特定时间发送消息? - Programming a Discord bot in Python- How do I make it send a message every day at a certain time? 用 Python 编写一个 Discord 机器人 - 如何让它自动发送消息? - Programming a Discord bot in Python- How do I make it automatically send messages? 用 Python 编写 Discord 机器人 - 如何让机器人对自己的消息做出反应? - Programming a Discord bot in Python- How do I make the bot react to its own message? 用 Python 编写 Discord 机器人 - 如何让机器人 ping @everyone? - Programming a Discord bot in Python- How do I make the bot ping @everyone? 在 Python 中编程 Discord 机器人 - 如何使机器人将命令限制到某个服务器? - Programming a Discord bot in Python- How do I make the bot restrict commands to a certain server? 用 Python 编写 Discord 机器人 - 如何在嵌入中缩进? - Programming a Discord bot in Python- How do I indent in embeds?
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM