我正在尝试创建一个机器人,该机器人将根据命令发送随机的gif(根据我选择的几个选项)。
但是,它总是作为错误返回,表示找不到命令,即使我键入了“拥抱和属性错误”也是如此:
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "hug" is not found
Ignoring exception in command hug:
Ignoring exception in command hug:
Traceback (most recent call last):
File "C:\Users\lemaia\Pictures\Discord\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\lemaia\Documents\DiscordBot\!givebot\v4.0.0.py", line 16, in hug
embed.random.choice(['https://media.discordapp.net/attachments/414964961953972235/570600544226508821/Server_Welcome.gif ', 'https://media.giphy.com/media/l4FGpP4lxGGgK5CBW/giphy.gif', 'https://media.giphy.com/media/fvN5KrNcKKUyX7hNIA/giphy.gif', 'https://tenor.com/view/milk-and-mocha-cuddling-hug-cute-kawaii-gif-12535135'])
AttributeError: 'Embed' object has no attribute 'random'"
embed.random.choice(['https://media.discordapp.net/attachments/414964961953972235/570600544226508821/Server_Welcome.gif ', 'https://media.giphy.com/media/l4FGpP4lxGGgK5CBW/giphy.gif', 'https://media.giphy.com/media/fvN5KrNcKKUyX7hNIA/giphy.gif', 'https://tenor.com/view/milk-and-mocha-cuddling-hug-cute-kawaii-gif-12535135'])
AttributeError: 'Embed' object has no attribute 'random'"
import discord
from discord.ext import commands
import random
client = commands.Bot(command_prefix='?')
@client.event
async def on_ready():
print("Bot is ready for use <3")
print(client.user.name)
print('------------------------')
@client.command()
async def hug(ctx):
embed = discord.Embed(title = 'A hug has been sent!', description = 'warm, fuzzy and comforting <3', color = 0x83B5E3)
embed.random.choice(['https://media.discordapp.net/attachments/414964961953972235/570600544226508821/Server_Welcome.gif ', 'https://media.giphy.com/media/l4FGpP4lxGGgK5CBW/giphy.gif', 'https://media.giphy.com/media/fvN5KrNcKKUyX7hNIA/giphy.gif', 'https://tenor.com/view/milk-and-mocha-cuddling-hug-cute-kawaii-gif-12535135'])
await ctx.channel.send(embed=embed)
client.run('TOKEN')
答案 0 :(得分:1)
您尝试使用random
对象的属性Embed
,而不调用random.choice
。
要设置嵌入图片,您需要使用discord.Embed.set_image
:
import discord
from discord.ext import commands
import random
client = commands.Bot(command_prefix='?')
@client.event
async def on_ready():
print("Bot is ready for use <3")
print(client.user.name)
print('------------------------')
@client.command()
async def hug(ctx):
image = random.choice(['https://media.discordapp.net/attachments/414964961953972235/570600544226508821/Server_Welcome.gif', 'https://media.giphy.com/media/l4FGpP4lxGGgK5CBW/giphy.gif', 'https://media.giphy.com/media/fvN5KrNcKKUyX7hNIA/giphy.gif', 'https://tenor.com/view/milk-and-mocha-cuddling-hug-cute-kawaii-gif-12535135']
embed = discord.Embed(title = 'A hug has been sent!', description = 'warm, fuzzy and comforting <3', color = 0x83B5E3)
embed.set_image(url=image))
await ctx.send(embed=embed)
client.run('TOKEN')
Context
对象具有send
属性,该属性基本上是Context.channel.send