簡體   English   中英

驗證通道-Discord.py

[英]Verification channel - Discord.py

我有一個“.verify”命令。 我有一個特殊的驗證渠道,我想讓機器人刪除每條消息,但不刪除嵌入和 .verify 命令。 我能以某種方式做到嗎?

.verify 的代碼:

@bot.command(pass_context=True)
async def verify(ctx):
    MEMBER = discord.utils.get(ctx.guild.roles, name= "♰・Member")
    UNVER = discord.utils.get(ctx.guild.roles, name= "♰・No Verification")
    embed=discord.Embed(title="<:oktagon:926853473251778601> Verification", description="You are now Verified!", color=0xe67e22)
    if ctx.channel.id == 926848096862887976:
      await ctx.author.add_roles(MEMBER)
      await ctx.author.remove_roles(UNVER)
      await ctx.message.delete()
      await ctx.send(embed=embed, delete_after=3)

對不起,如果我沒有理解正確,但我想如果他們的author是用戶並且消息不是“.verify”,或者如果作者是機器人,但消息沒有'沒有嵌入。 您可以使用ctx.author.bot來檢查作者是否是機器人(返回布爾值)和ctx.embeds來檢查消息是否有嵌入(返回消息中的嵌入列表,我們檢查嵌入的數量是否為0)。

@bot.event
async def on_message(ctx):
    user = ctx.author #Just a member, can be a bot or a user. The author of the message.
    if user.bot: #Check if the author is a bot.
        if not ctx.embeds: #Check if embeds are not there in the message.
            print("Deleting because it's a message sent by a bot but doesn't have embeds")
            await ctx.delete()
    elif not user.bot: #Check if the author of the message is a user.
        if ctx.content != ".verify": #Check if the message is not exactly ".verify" (the verify message/command sent by the user).
            print("Deleting because it's not .verify")
            await ctx.delete()

print()命令僅供您參考和記錄。 如果您想要更好的性能,您可以刪除它們。 檢查文檔以獲得更好的理解。

是的。 我試過了,但現在 my.verify 命令不起作用。 控制台中的任何錯誤。 現在要做什么?

@bot.command(pass_context=True)
async def verify(ctx):
    MEMBER = discord.utils.get(ctx.guild.roles, name= "♰・Member")
    UNVER = discord.utils.get(ctx.guild.roles, name= "♰・No Verification")
    embed=discord.Embed(title="<:oktagon:926853473251778601> Verification", description="You are now Verified!", color=0xe67e22)
    if ctx.channel.id == 926848096862887976:
      await ctx.author.add_roles(MEMBER)
      await ctx.author.remove_roles(UNVER)
      await ctx.message.delete()
      await ctx.send(embed=embed, delete_after=3)

@bot.event
async def on_message(ctx):
    user = ctx.author
    if user.bot:
     if ctx.channel.id == 926848096862887976:
        if not ctx.embeds:
            print("Deleting because it's a message sent by a bot but doesn't have embeds")
            await ctx.delete()
    elif not user.bot:
     if ctx.channel.id == 926848096862887976:
        if ctx.content != ".verify":
            print("Deleting because it's not .verify")
            await ctx.delete()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM