Oke jadi pada dasarnya saya ingin membuatnya agar bot kembali dengan "Siapa infonya bruh" jika tidak ada yang disebutkan dalam pesan

@bot.command(pass_context=True)
async def info(ctx, user: discord.Member):
    if user == None:
        await ctx.channel.send("**Who's info bruh**")
        return
    embed = discord.Embed(title="{}'s info".format(user.name), description="Here's what i could find", color=colorran)
    embed.add_field(name="Name", value=user.name, inline=True)
    embed.add_field(name="ID", value=user.id, inline=True)
    embed.add_field(name="Status", value=user.status, inline=True)
    embed.add_field(name="Highest Role", value=user.top_role)
    embed.add_field(name="Joined", value=user.joined_at.__format__('%A, %d. %B %Y'))
    embed.set_thumbnail(url=user.avatar_url)
    embed.set_footer(text=f"Local Meme Bot Development - Requested By: {ctx.author}", icon_url=ctx.author.avatar_url)
    await ctx.send(embed=embed)

Kode ini kembali dengan

discord.ext.commands.errors.MissingRequiredArgument: user is a required argument that is missing.
1
HijakTheMiner 20 Mei 2020, 18:11

1 menjawab

Jawaban Terbaik

Anda dapat mengatur argumen default jika tidak ada yang dilewatkan, seperti like

@bot.command() # context is automatically passed in rewrite
async def info(ctx, user: discord.Member = None):
    if not user: # more pythonic way of checking if a value is None
        await ctx.send("**Whose info?**") # or you can set user = ctx.author, up to you
    else:
        embed = discord.Embed(title="{}'s info".format(user.name), description="Here's what i could find", color=colorran)
        embed.add_field(name="Name", value=user.name, inline=True)
        embed.add_field(name="ID", value=user.id, inline=True)
        embed.add_field(name="Status", value=user.status, inline=True)
        embed.add_field(name="Highest Role", value=user.top_role)
        embed.add_field(name="Joined", value=user.joined_at.__format__('%A, %d. %B %Y'))
        embed.set_thumbnail(url=user.avatar_url)
        embed.set_footer(text=f"Local Meme Bot Development - Requested By: {ctx.author}", icon_url=ctx.author.avatar_url)
        await ctx.send(embed=embed)

Atau, Anda dapat menangkap kesalahan:

@bot.command()
async def info(ctx, user: discord.Member):
    # embed-setting code
@info.error
async def info_error(ctx, error):
    if isinstance(error, discord.ext.commands.MissingRequiredArgument):
        await ctx.send("**Whose info?**")
    else:
        print(error)

Referensi:

1
Diggy. 20 Mei 2020, 15:57