Reputation: 45
I am here with an annoying error when I use this code. I use this code for other commands like slap, hug, kiss, etc. I reuse this code a lot and it seems like the more I put the more errors I get...
Code:
@client.command()
async def feed(ctx, member:discord.User=None):
feedGIF = [
"https://i.imgur.com/1vC0R20.gif",
"https://data.whicdn.com/images/81561319/original.gif",
"https://thumbs.gfycat.com/EagerSpectacularHoverfly-max-14mb.gif",
"https://64.media.tumblr.com/4d160635539ef31d8b058bc3e35a907c/tumblr_p4e113SOw91wn2b96o1_400.gifv",
"https://i.pinimg.com/originals/7a/cb/20/7acb209c594f42e0d56b87d70421c85d.gif",
]
feedSelfResponse = [
f"{ctx.author.mention} feeds them selves. So eating?",
f"{ctx.author.mention} feeds themselves yum!",
f"{ctx.author.mention} is feeding their hungry stomach",
f"{ctx.author.mention} is being fed by... themselves",
]
feedResponse = [
f"{ctx.author.mention} feeds {member.mention}",
f"{member.mention} is being feed by {ctx.member.mention}. Open wide!",
f"Yum! {ctx.member.mention} feeds {member.mention}. Here comes the airplane!",
]
if (member == ctx.message.author or member == None):
feed = f"{random.choice(feedSelfResponse)}"
else:
feed = f"{random.choice(feedResponse)}"
embed = discord.Embed(color=0x9b59b6)
embed.set_image(url=f"{random.choice(feedGIF)}")
embed.add_field(name="Feed", value=(feed))
await ctx.send(embed=embed)
Error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'member'
I have no idea how to fix this please help!
Upvotes: 1
Views: 612
Reputation: 30
So I think I have fixed your command
import random
@client.command()
async def feed(ctx, member:discord.Member = None):
feedGIF = [
"https://i.imgur.com/1vC0R20.gif",
"https://data.whicdn.com/images/81561319/original.gif",
"https://thumbs.gfycat.com/EagerSpectacularHoverfly-max-14mb.gif",
"https://64.media.tumblr.com/4d160635539ef31d8b058bc3e35a907c/tumblr_p4e113SOw91wn2b96o1_400.gifv",
"https://i.pinimg.com/originals/7a/cb/20/7acb209c594f42e0d56b87d70421c85d.gif",
]
if (member == ctx.author or member == None):
feedSelfResponse = [
f"{ctx.author.mention} feeds them selves. So eating?",
f"{ctx.author.mention} feeds themselves yum!",
f"{ctx.author.mention} is feeding their hungry stomach",
f"{ctx.author.mention} is being fed by... themselves",
]
feed = random.choice(feedSelfResponse)
embed = discord.Embed(color=0x9b59b6)
embed.set_image(url=random.choice(feedGIF))
embed.add_field(name="Feed", value=(feed))
await ctx.send(embed=embed)
else:
feedResponse = [
f"{ctx.author.mention} feeds {member.mention}",
f"{member.mention} is being feed by {ctx.author.mention}. Open wide!",
f"Yum! {ctx.author.mention} feeds {member.mention}. Here comes the airplane!",
]
feed = random.choice(feedResponse)
embed = discord.Embed(color=0x9b59b6)
embed.set_image(url=random.choice(feedGIF))
embed.add_field(name="Feed", value=(feed))
await ctx.send(embed=embed)
I'm thinking the error was that Python reads the command from top to bottom so it tried to fill the the {ctx.author.mention}
, but the member = None.
Upvotes: 1