F
F
FurryFandom2021-02-18 15:44:42
Python
FurryFandom, 2021-02-18 15:44:42

How to simplify code in Embed?

I tried to write a code so that when the >usercheck command is given, the bot would display a message where it shows information about the user (not through mentions, but through NickName) through the embed. Is it possible to somehow simplify and make it so that the bot finds a recorded nickname somewhere and gives information on it recorded in the code.

client.command(pass_context = True)
@commands.has_permissions(administrator = True)
async def checkuser_user(ctx):
    await ctx.channel.send('Please, wait')
    PREFIX = '>'
    emb = discord.Embed(title = 'User info')

    emb.add_field(name = '{}Bans'.format(PREFIX),value = '0')
    emb.add_field(name = '{}Kicks'.format(PREFIX),value = '0')
    emb.add_field(name = '{}Warns'.format(PREFIX),value = '1/3')
    emb.add_field(name = '{}Ban reason: '.format(PREFIX),value = 'None')
    emb.add_field(name = '{}Role history'.format(PREFIX),value = 'Verify.')
    await ctx.send(embed = emb)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
retUrn3d, 2021-02-18
@FurryFandom

I made such a solution for you, but this is not a panacea and it will not find nicknames like: "Nick Name" .
But for that it will work fine for nicknames like: "Nickname" .

@bot.command(pass_context = True)
@commands.has_permissions(administrator = True)
async def checkuser_user(ctx, arg):
    await ctx.channel.send('Please, wait')
    # Пребираем все пользователей на сервере.
    for guild in bot.guilds:
        for member in guild.members:
            # Сравниваем введенный ник и ники тех кто есть на сервере, убирая идентификатор из ника "#9999" 
            if arg == str(member)[0:-5]:
                PREFIX = '>'
                emb = discord.Embed(title = 'User info')

                emb.add_field(name = '{}Bans'.format(PREFIX),value = '0')
                emb.add_field(name = '{}Kicks'.format(PREFIX),value = '0')
                emb.add_field(name = '{}Warns'.format(PREFIX),value = '1/3')
                emb.add_field(name = '{}Ban reason: '.format(PREFIX),value = 'None')
                emb.add_field(name = '{}Role history'.format(PREFIX),value = 'Verify.')
                await ctx.send(embed = emb)

And the second option using the package: fuzzywuzzy
This option allows you to more flexibly search for the right users, including if a minor mistake in writing a nickname is made.
from fuzzywuzzy import fuzz

@bot.command(pass_context = True)
@commands.has_permissions(administrator = True)
async def checkuser_user(ctx, arg):
    await ctx.channel.send('Please, wait')
    # Пребираем все пользователей на сервере.
    for guild in bot.guilds:
        for member in guild.members:
            # Сравниваем введенный ник и ники полученные из списка.
            if fuzz.partial_ratio(arg, str(member)[0:-5]) > 95:  # <- Процент при котором совпадение "успешно".
                PREFIX = '>'
                emb = discord.Embed(title = 'User info')

                emb.add_field(name = '{}Bans'.format(PREFIX),value = '0')
                emb.add_field(name = '{}Kicks'.format(PREFIX),value = '0')
                emb.add_field(name = '{}Warns'.format(PREFIX),value = '1/3')
                emb.add_field(name = '{}Ban reason: '.format(PREFIX),value = 'None')
                emb.add_field(name = '{}Role history'.format(PREFIX),value = 'Verify.')
                await ctx.send(embed = emb)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question