繁体   English   中英

Discord.py - 等待用户消息

[英]Discord.py - Await for user's message

所以现在我正在尝试创建一种应用程序机器人,现在我用于机器人的检查不允许用户进入下一个问题。 没有回溯,所以它与我定义的检查有关。

@commands.command()
  @commands.has_role("Realm OP")
  async def block(self, ctx, user: discord.User):
    DMchannel = await ctx.author.create_dm()
    channel = ctx.message.channel
    author = ctx.message.author
    mentions = [role.mention for role in ctx.message.author.roles if role.mentionable]
    channel2 = str(channel.name)
    channel = channel2.split('-')
    if len(channel2) == 2: # #real-emoji
      realm, emoji = channel
    else: # #realm-name-emoji  
      realm, emoji = channel[0], channel[-1]
      realmName = realm.replace("-" , " ")
      realmName1 = realmName.lower()
    rolelist = []
    print(realmName1)
    a = solve(realmName1)
    print(a)
    realmName2 = str(a) + " OP"
    print(realmName2)
    check_role = discord.utils.get(ctx.guild.roles, name= realmName2)
    if check_role not in ctx.author.roles:
      return await ctx.send('You do not own this channel')

    else:
      await ctx.send("You own this channel!")
      def check(m):
        return m.channel == channel and m.author != self.bot.user
        
      await DMchannel.send("Please fill out the questions in order to block the user!")

      await DMchannel.send("User's Gamertag: (If you don't know, try using the >search command to see if they have any previous records!) ")
      blocka1 = await self.bot.wait_for('message', check=check)

      await DMchannel.send("Reason for block:")
      blocka2 = await self.bot.wait_for('message', check=check)

现在,在用户回答第一个问题并且没有回溯之后,机器人不会做任何事情。

任何帮助或建议都会有很大帮助!

你的支票没有返回任何东西。 它应该return TrueFalse 这意味着您的wait_for永远不会结束(因为check永远不会返回True ),所以它永远不会问下一个问题。

def check(m):
  return m.channel == channel and m.author != self.bot.user

编辑:

您的channelctx.channel ,而您的机器人在 DM 中等待答案。 假设你也在 DM 中回答你的机器人,这意味着你的check永远不会通过,因为m.channel永远不会等于channel

def check(m):
  return m.guild is None and m.author == ctx.author

这将检查是否在 DM 中发送了消息( GuildNone ),以及它是否是原作者的 DM。

暂无
暂无

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

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