Reputation: 3
@bot.command()
async def catto(ctx):
choice = ["1","2"]
print(random.choice(choice))
if choice == 1:
r = requests.get("APILINK").json()
cat_embed = discord.Embed()
cat_embed.set_image(url=r["url"])
await ctx.send(embed=cat_embed)
else:
file = discord.File("FILEPATH")
file2 = discord.File("FILEPATH")
cats = (file, file2)
await ctx.send(embed = random.choice(cats))
It's in the else bit Im having problems where it gives me the error as said in the title.
Full Traceback as suggested:
Ignoring exception in command catto:
Traceback (most recent call last): File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "c:\Users\OneDrive\Documents\Programming-Extra\Discord Bot\BOTNAME", line 46, in catto await ctx.send(embed = random.choice(cats)) File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\abc.py", line 1017, in send embed = embed.to_dict() AttributeError: 'File' object has no attribute 'to_dict'
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'File' object has no attribute 'to_dict
Upvotes: 0
Views: 988
Reputation: 4092
The error is with the last line:
await ctx.send(embed = random.choice(cats))
It should be like this instead:
await ctx.send(embed=discord.Embed(file=random.choice(cats))
or like this:
await ctx.send(file=random.choice(cats))
Upvotes: 1