Discord Bot DM 问卷 discord py

时间:2021-03-05 20:05:19

标签: python discord discord.py

我基本上是在尝试制作一个应用程序/问卷不和谐机器人。当被触发时,bot 应该通过 dm 通知用户并询问用户是否想要继续。用户回复“继续”,机器人从第一个问题开始,等待用户的回复。然后机器人接收响应并存储它并继续下一个问题,它会循环直到完成最后一个问题。我被困在机器人发送第一个问题的部分,当我回答时我没有得到任何回应。任何帮助将不胜感激。

附注。我对 python 和 discord py 还很陌生

@bot.command()
async def apply(ctx):
    Name = ''
    Age = ''
    user = ctx.author
    name = ctx.author.display_name
    q = ['What is your full real name?',
                 'What is your age?']
    i = 0
#embed
    message = 'Thank you ' + name + \
    ' for taking interest in Narcos City Police Department. You will be asked a series of question which you are required to answer to the fullest of your ability.   Please reply with *proceed* to start your application.'
    embedmsg =discord.Embed(title = 'NARCOS CITY POLICE DEPARTMENT', color = Police)
    embedmsg.set_thumbnail(url = thumbnail)
    embedmsg.add_field(name = 'Human Resources:', value = message)

#initial bot response
    dmchannel = await ctx.author.send(embed=embedmsg)

#check
    def check(m):
        return m.author == ctx.author and m.channel == ctx.author.dm_channel
    msg = await bot.wait_for('message', check=check)
    if msg.content == 'proceed':
            async def askq(q):
                await ctx.author.send(q)
                msg
                return msg.content
            Name = await askq(q[0])
            Age = await askq(q[1])

1 个答案:

答案 0 :(得分:0)

你的支票功能有点乱。您可以尝试以下操作:

class Category {
    public Integer primaryKey;
    public String parentId;
    public Integer depth;
    public String categoryId;
    public String name;
    public String pluralName;
    public String shortName;
    @Ignore public List<Category> categories;
}

我在代码中做了什么?

  • 内置不同的检查以确保答案是由命令作者在 DM 频道中发送的
  • 将答案放入列表 (for(Category category: categories){ List<Category> tree = new ArrayList<>(); buildCategoryClosureTable(category, tree, 0); } void buildCategoryClosureTable(Category target, List<Category> tree, Integer depth){ tree.add(target); if(!target.categories.isEmpty()){ depth++; do{ Category category = target.categories.remove(0); buildFoursquareCategoryClosureTable(category, tree, depth); }while(!target.categories.isEmpty()); } for(Category category : tree){ FoursquareCategory foursquareCategory = new FoursquareCategory(target, category.categoryId, depth); insertFoursquareCategoryIntoBaseTable(foursquareCategory); depth--; } tree.remove(target); } )
  • 将答案以嵌入方式发送到您选择的频道

<强>!!请注意,使用此方法,机器人将直接开始询问您的问题!!

如果您想先询问用户是否想从以下问题开始:

    @bot.command
    async def apply(ctx):
        await ctx.author.send("Filler") # Sends a message to the author

        questions = ["", "", ""] # Create your list of answers

        answers = [] # Empty list as the user will input the answers

        def check(m):
            return ctx.author == m.author and isinstance(m.channel, discord.DMChannel) # Check that the messages were sent in DM by the right author

        for i in questions:
            await ctx.author.send(i) # Sends the questions one after another
            try:
                msg = await bot.wait_for('message', timeout=XXX, check=check)
            except asyncio.TimeoutError:
                await ctx.author.send("Timeout message.")
                return # Will no longer proceed, user has to run the command again
            else:
                answers.append(msg) # Appends the answers, proceed

        [OPTIONAL PART]
        channel = bot.get_channel(ChannelID)
        e = discord.Embed(color=ctx.author.color)
        e.title = "New application"
        e.description = f"First answer: {answers[0].content} [...]"
        await channel.send(embed=e)