Devalart
Devalart

Reputation: 63

Discord.PY Warn command reason is spaced out

spaced out

Trying to make a warn command, and the reason part is spaced out.

@bot.command(pass_context = True)
async def warn(ctx, user:discord.User, *, reason="None"):
    if ctx.message.author.guild_permissions.manage_messages:
        if not reason:
            await ctx.send("Please provide a reason")
            return
        reason = ' '.join(reason)
        for current_user in report['users']:
            if current_user['name'] == user.name:
                current_user['reasons'].append(reason)
                break
        else:
            report['users'].append({
                'name':user.name,
                'reasons': [reason,]
                })
        with open('vnreports.json','w+') as f:
            json.dump(report,f)
            await ctx.send(f"Succesfully reported {user} for {reason}")
        await logs(member=f'{user}', action='warned', reason=f'{reason}', mod=ctx.author)
    else:
        await ctx.send("no")
        return

Above is the code for said command. "logs" is a function that works perfectly with everything else.

async def logs(member, action, reason, mod):
    channel = bot.get_channel(801989689149882388)
    embed = discord.Embed(title=f"Audit Channel Post", description="---")
    embed.add_field(name=f"{member} has been {action}", value=f"Reason is {reason}", inline=False)
    embed.add_field(name=f"Action was done by:", value=f"{mod}", inline=False)
    embed.set_footer(text=f"Bot made by @vito#1000")
    await channel.send(embed=embed)

Upvotes: 1

Views: 528

Answers (2)

ChrisDewa
ChrisDewa

Reputation: 642

reason = ' '.join(reason)

This is the problem. That is what is inserting the spaces in the line and it actually isn't necessary. Reason is already a string. So you can just delete that line.

Or comment what exactly was that line supposed to do..

Also

@bot.command(pass_context = True)

pass_context Is no longer necessary since a few versions back. Just do @bot.command()

Upvotes: 1

Nurqm
Nurqm

Reputation: 4743

It's because of ' '.join(reason). reason is already a string, there's no reason to do that. But if it was a list, you could do ''.join(reason). With that way, it won't add spaces between characters. You just have to remove this line:

@bot.command(pass_context = True)
async def warn(ctx, user:discord.User, *, reason="None"):
    ...
    reason = ' '.join(reason) # This line has to be removed.
    ...

Upvotes: 5

Related Questions