首页 > 解决方案 > 如何让不和谐机器人通过命令发送某些图像?

问题描述

import discord
import random
from discord.ext import commands

#client (my bot)
client = commands.Bot(command_prefix = "!")

@client.event
async def on_ready():

main_channel = client.get_channel(channel_id)
await main_channel.send('bot is ready')

@client.command()
async def ping(ctx):
    await ctx.send(f'My Ping is {round(client.latency * 1000)}ms')

我希望有一个像'!png dice'这样的命令,然后它会给你一个骰子的png。我不知道我是否必须列出清单,将清单放在哪里,或者是否从网络上获取图像。这是我第一次真正编写机器人代码,而且我对编码也很陌生。如果您能够提供帮助,您可以简化它以便我理解。

我正在考虑使用它,但它没有用:

@client.command()
async def png(ctx)
await ctx.send(url of image)

但它没有用。我的代码也无法知道想要什么图像。

标签: pythondiscord.py

解决方案


好吧,它会是这样的

@client.command()
async def png(ctx):
    await ctx.send(url of image)

此外,我会尝试找到一个可以输入单词并找到照片的 API。很容易找到你可以使用https://www.microsoft.com/en-us/bing/apis/bing-image-search-api。我想这就是你想要的。


推荐阅读