python - 如何让不和谐机器人通过命令发送某些图像?
问题描述
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)
但它没有用。我的代码也无法知道想要什么图像。
解决方案
好吧,它会是这样的
@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。我想这就是你想要的。
推荐阅读
- python - 如何在人脸识别的KNN算法中获取匹配图像的百分比
- node.js - 如何确保一个异步功能在另一个异步功能在 NodeJS 中启动之前完成?
- sql - 使用 UUID 列设置大查询表?
- c++ - 从自定义 wxButton 中删除边框
- python-3.x - 将 tensorflow.keras 模型转换为 keras 模型
- javascript - 一旦手势开始,即使我向其添加偏移值,PanGestureHandler translationY 也会重置为 0。这怎么可能?
- mysql - MySQL 在 XAMPP(v3.2.4) 中意外关闭,而 Apache 工作正常
- reactjs - 如何做 Storybook React Material UI 自定义样式
- php - 如何将此动态构造的 URL 添加到 PHP 变量?
- python - VGG 模型的输出在训练后变得恒定并且损失/准确率没有提高