簡體   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