【发布时间】:2018-09-11 18:37:35
【问题描述】:
我一直在寻找一种方法来对我的 Discord 机器人进行编码,以提及被某个命令标记的用户,并发送图像/gif 以与消息一起发送。到目前为止,我能够从一个命令生成随机图像并使用不同的命令提及用户。我只需要弄清楚如何为一个命令实现两者。
这是我用来从一个命令生成随机图像的代码:
client = Bot(command_prefix=BOT_PREFIX)
@client.event
async def on_message(message):
if message.content.upper().startswith("?DOG"):
jessie1 = "https://cdn.discordapp.com/attachments/432563417887277060/484484259386621993/22B25E7A-3157-4C23-B889-47ECFE8A15A9.jpg"
snowy = "https://cdn.discordapp.com/attachments/487045791697862666/487390822485065749/824B6151-E818-49A4-A564-C2C752ED6384.jpg"
await client.send_message(message.channel, random.choice([snowy, jessie1]))
这是我曾经提到另一个用户的代码:
elif message.content.upper().startswith('?GIVE BANANA'):
user = message.mentions[0]
responses = ["{} gave a banana to {} :banana:"]
choice = random.choice(responses)
choice = choice.format(message.author.mention, user.mention)
await client.send_message(message.channel, choice)
在第二个代码中,我不知道如何使用它添加图像。最好,我想用它生成随机图像,这就是我提供两个代码示例的原因。
【问题讨论】:
标签: python-3.x discord discord.py