The Wizards Room
The Wizards Room

Reputation: 1

Report command with discord python

I am trying to create a report command that sends a message to a channel. Such as *report username#1234 reasoning is put here etc etc etc.

channel receives it by {user} reported by {author} for {reason}. and a private message is sent to the author telling them the report went through.

However if the reported user has the "kick" permission then its also sent to a second channel. And a private message sent to me the owner. Structured the same as {user} reported by {author} for {reason}.

But... I keep getting some weird errors, like bots not defined (even though it is defined).

    async def report(self, ctx, user, *, reason=None):
        logger = bot.get_channel(644966241835941898)
        channel = bot.get_channel(641639710183129113)
        if reason is None:
            await ctx.author.send('Hey I get that you are trying to report someone but I need a reason. Please try again.')
        elif ctx.message.author.guild_permissions.read_messages:
            await ctx.channel.send(f'{user} reported by {author} for {reason}')
        elif user.guild_permissions.kick_members:
            await ctx.logger.send(f'{user}, reported by {author} for {reason}')
            await ctx.channel.send(author, user, reason)
            await ctx.author.send("""Im going to put this in a safe spot for the wizard himself to review.""")```

Upvotes: 0

Views: 2834

Answers (1)

nxfi777
nxfi777

Reputation: 91

Your need to make the user argument look like this: user : discord.Membersand the reason argument to take all inputs after the user. I'm not sure what the point of having a logger and a channel is.

async def report(self, ctx, user : discord.Member, *reason):
    channel = self.bot.get_channel(your channel id) #since it's a cog u need self.bot
    author = ctx.message.author
    rearray = ' '.join(reason[:]) #converts reason argument array to string
    if not rearray: #what to do if there is no reason specified
        await channel.send(f"{author} has reported {user}, reason: Not provided")
        await ctx.message.delete() #I would get rid of the command input
    else:
        await channel.send(f"{author} has reported {user}, reason: {rearray}")
        await ctx.message.delete()

Extra

If you want a special report for people with kick perms it would be something like Permissions.kick_members for the if statement. You can find it easily in the api.

Next time do more research but if u need anything just comment :)

Upvotes: 1

Related Questions