等待语句不输出消息

时间:2018-09-10 12:04:07

标签: python python-3.x discord discord.py

嗨,我的代码行有一个难题,该行未输出消息。

应如何工作

如果潜伏者角色在成员角色中返回我发现有些潜伏者准备好被踢了,你想踢他们吗?。 -否则,如果没有潜伏者的成员返回今天没有潜伏者要踢。

我遇到的问题是消息:今天没有潜伏者正在输出。

以下是我正在与您合作的想法,以帮助您了解要实现的目标:

@commands.command(pass_context=True, no_pm=True)
@checks.is_owner()
async def check_lurkers(self, ctx, *_):
    """Manually check for lurkers"""

    serverid = '465536300452151298'
    server = self.bot.get_server(serverid) # Soon to change to ctx.message.server
    lurker_role = discord.utils.get(server.roles, name="Lurker")
    member_role = discord.utils.get(server.roles, name="Members")
    any_lurkers = False
    for member in list(server.members):
        if member_role not in member.roles and lurker_role in member.roles:
            await self.bot.say("I've found some lurkers ready to be kicked, would you like to kick them?")
            msg = await self.bot.wait_for_message(timeout=10)
            if msg is None or msg.content.lower().strip() in ("no", "n"):
                await self.bot.say("No lurkers were kicked.")

            elif msg.content.lower().strip() in ("yes", "y"):
                await self.bot.kick(member)
                any_lurkers=True
            if any_lurkers:
                await self.bot.say("Adios lurkerinos! :wave:")
            else:
                await self.bot.say("No lurkers around to kick today. :raised_hands: ")

else: await self.bot.say("No lurkers around to kick today. :raised_hands: ")

这是不输出任何内容的行。我在这里做什么错了?

我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

在这里,我们建立了潜伏者列表,然后决定是否将其踢出。请注意,决定是否踢球的决定只发生在循环之外一次。

@commands.command(pass_context=True, no_pm=True)
@checks.is_owner()
async def check_lurkers(self, ctx):
    """Manually check for lurkers"""

    serverid = '465536300452151298'
    server = self.bot.get_server(serverid) # Soon to change to ctx.message.server
    lurker_role = discord.utils.get(server.roles, name="Lurker")
    member_role = discord.utils.get(server.roles, name="Members")
    any_lurkers = False
    lurkers = [member for member in server.members 
               if member_role not in member.roles and lurker_role in member.roles]
    if lurkers:
        await self.bot.say("I've found some lurkers ready to be kicked, would you like to kick them?")
        msg = await self.bot.wait_for_message(timeout=10)
        if msg is None or msg.content.lower().strip() not in in ("yes", "y"):
            await self.bot.say("No lurkers were kicked.")
        else:
            for lurker in lurkers:
                await self.bot.kick(lurker)
            await self.bot.say("Adios lurkerinos! :wave:")
    else:
        await self.bot.say("No lurkers around to kick today. :raised_hands: ")