簡體   English   中英

Discord.py:如何在頻道中等待新消息並將其內容用於另一個嵌入

[英]Discord.py: How to wait for new message in channel and use its content for another embed

我最近一直在構建一個帶有一些特殊命令的機器人。

APPEAL 命令是現在有問題的命令。

指揮部的工作是什么?

它必須發送一個嵌入並提及所有必須在頻道中輸入的內容才能讓 BOT 獲得它。 這就是機器人。

代碼:

@nd.command()
async def appeal(ctx):
    if ctx.channel.id == 836811104424296480:
        appealinfoembed=discord.Embed(title="Appeal", description=f"Hi {ctx.author.mention}, you are appealing for verification. Now, the verification system works like this, unless you are verified, you can't send messages in the server except this category. So, if you are a town member and you want to send messages and use other features, then get verified. Thus, use this command. \n \nYou need to submit the following data in order to get verified. This data will be looked over by our Town Council and they will verify you soon. This is the format: \n```Real Name: \nIn game name: \nAge: \nSex: M/F/T \n \nTown Joing Date: \nExperience: 'Add you experience in the Towny Servers, anywhere you played, in brief.'```", color=discord.Colour.random())
        appealinfoembed.set_author(name="xXMiaraXx")
        appealinfoembed.set_footer(text=datetime.datetime.now())
        await ctx.channel.send(embed=appealinfoembed)
        
        await ctx.channel.send("Your next message after this text will be considered as the information asked before. Please enter all the details in one single message, otherwise the verification will not work.")

        appealchannel = nd.get_channel(836811104424296480)
        
        if member_details == await appealchannel.fetch_message(appealchannel.last_message_id):
            memberdetailsembed=discord.Embed(title=f"Appeal by - {ctx.author.mention}", description=member_details, color=discord.Colour.random())
            memberdetailsembed.set_author(name="xXMiaraXx")
            memberdetailsembed.set_footer(text=datetime.datetime.now())
            await appealchannel.send(embed=memberdetailsembed)

    else:
        return

問題:

上訴通道變量上面的代碼工作正常,因為它是正確的,但它之后的任何東西都不起作用。 它只是沒有做任何事情。 之后發布的任何消息都沒有被接收,或者我不知道會發生什么。 我沒有得到錯誤的實際位置。


答案可能不一定針對此代碼的類型。 請做任何事情讓我清楚並工作。

問題是,您的機器人在編寫消息時會立即在頻道中獲取最新消息,並且沒有人可以輸入這么快。 要解決這個問題,你可以使用wait_for() ,在前面添加這個appealchannel = nd.get_channel(836811104424296480)

def check(msg):
        return msg.author == ctx.author and msg.channel == ctx.channel
try:
    answer = await nd.wait_for("message", check=check, timeout=600.0)#you can add any timeout in seconds there, for an appeal bot I would recommend something like 15 minutes
except asyncio.TimeoutError:
    await ctx.send("Your time is up") #Do stuff here when the time runs out

這應該可以解決您的問題,因為我不知道您從哪里獲得變量 member_details。 因此,不要使用 member_details,而是使用 answer.content 並刪除if member_details == await appealchannel.fetch_message(appealchannel.last_message_id):所以你的最終代碼是:

@nd.command()
async def appeal(ctx):
    if ctx.channel.id == 836811104424296480:
        appealinfoembed=discord.Embed(title="Appeal", description=f"Hi {ctx.author.mention}, you are appealing for verification. Now, the verification system works like this, unless you are verified, you can't send messages in the server except this category. So, if you are a town member and you want to send messages and use other features, then get verified. Thus, use this command. \n \nYou need to submit the following data in order to get verified. This data will be looked over by our Town Council and they will verify you soon. This is the format: \n```Real Name: \nIn game name: \nAge: \nSex: M/F/T \n \nTown Joing Date: \nExperience: 'Add you experience in the Towny Servers, anywhere you played, in brief.'```", color=discord.Colour.random())
        appealinfoembed.set_author(name="xXMiaraXx")
        appealinfoembed.set_footer(text=datetime.datetime.now())
        await ctx.channel.send(embed=appealinfoembed)
        
        await ctx.channel.send("Your next message after this text will be considered as the information asked before. Please enter all the details in one single message, otherwise the verification will not work.")
        def check(msg):
                return msg.author == ctx.author and msg.channel == ctx.channel
        try:
            answer = await nd.wait_for("message", check=check, timeout=600.0)#you can add any timeout in seconds there, for an appeal bot I would recommend something like 15 minutes
        except asyncio.TimeoutError:
            await ctx.send("Your time is up") #Do stuff here when the time runs out
        memberdetailsembed=discord.Embed(title=f"Appeal by - {ctx.author.mention}", description=answer.content, color=discord.Colour.random())
        memberdetailsembed.set_author(name="xXMiaraXx")
        memberdetailsembed.set_footer(text=datetime.datetime.now())
        appealchannel = nd.get_channel(836811104424296480)
        await appealchannel.send(embed=memberdetailsembed)

參考:

暫無
暫無

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

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