K
K
Killir Vanya2292021-07-15 15:58:32
Python
Killir Vanya229, 2021-07-15 15:58:32

How do I do error handling in the invite command?

The bottom line is that the bot should give an error if the participant does not have invites on the server, the problem looks like this:
60f030ccdac4b164784835.png
Here is my invite code:

@commands.command(name = "invites", aliases = ("check_invites", "invites_check", "приглашения"))
    async def user_invites(self, ctx: commands.Context, member: discord.Member = None) -> None:
        if member is None:
            member = ctx.author

        embed = discord.Embed(color=defualt)

        for invite in await ctx.guild.invites():
            if invite.inviter.id == member.id:

                day_created = (datetime.now()-invite.created_at).days
                day_text_created = day_member(invite.created_at)

                embed.add_field(name = f"Код {invite.code}", value =
                f"На: {invite.channel.mention}\n"
                f"Зашло: {invite.uses}\n"
                f"Создан: {day_created} {day_text_created}")

        embed.set_author(name = f"Приглашения у {member.name}", icon_url = member.avatar_url)
        await ctx.send(embed = embed)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-07-15
@VEYREN

Regular flag, the simplest logical action

has_invites = False

for invite in await ctx.guild.invites():
    if invite.inviter.id == member.id:
        has_invites = True

if not has_invites:
    # ошибка
else:
    await ctx.send(embed = embed)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question