【发布时间】:2021-09-09 02:52:38
【问题描述】:
我尝试使用 discord.py 制作一个不和谐机器人,当它看到命令“.pic”时会发送图片。当我运行程序并尝试 .pic 命令时,图片不发送,嵌入也不发送。我有一个做冷却的小程序。即使嵌入和图片不存在,我确实看到冷却功能起作用。我在控制台中也没有收到错误代码 这是我的代码:
import discord
import random
from discord.ext import commands
client = commands.Bot(command_prefix = ".")
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.errors.CommandOnCooldown):
return await ctx.send('The command **{}** is still on cooldown for {:.2f}'.format(ctx.command.name, error.retry_after))
pictures =["https://i.imgur.com/LAmHP4K.jpg","https://i.imgur.com/sXS290O.jpg","https://i.imgur.com/Ar7Ihs5.jpg"]
@client.command()
@commands.cooldown(1, 2, commands.BucketType.user)
async def pic(ctx):
embed = discord.Embed(color = discord.colour.red())
random_link = random.choice(pictures)
embed.set_image(url = random_link)
await ctx.send(embed = embed)
client.run("TOKEN")
【问题讨论】:
-
ctx.send是协程,应该等待 -
我将代码更改为 ctx.send(embed = embed) 但仍然无法正常工作
标签: python discord discord.py bots