繁体   English   中英

使用 discord python 报告命令

[英]Report command with discord python

我正在尝试创建一个向频道发送消息的报告命令。 例如 *report username#1234 推理放在这里等等等等。

频道由 {author} 为 {reason} 报告的 {user} 接收它。 并且向作者发送了一条私人消息,告诉他们报告已通过。

但是,如果报告的用户具有“踢”权限,那么它也会发送到第二个频道。 并且私信给我发了楼主。 结构与 {author} 针对 {reason} 报告的 {user} 相同。

但是...我不断收到一些奇怪的错误,例如未定义的机器人(即使已定义)。

    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.""")```

您需要使用户参数看起来像这样: user: discord.Members和原因参数以在用户之后获取所有输入。 我不确定拥有记录器和频道的意义是什么。

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()

额外的

如果你想要一份针对有踢权限的人的特别报告,那么 if 语句将类似于 Permissions.kick_members。 您可以在 api 中轻松找到它。

下次做更多的研究,但如果你需要任何东西,请评论:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM