gpt4 book ai didi

python - 等待语句不输出消息

转载 作者:行者123 更新时间:2023-12-01 09:03:39 24 4
gpt4 key购买 nike

您好,我的一行代码没有输出消息,但遇到了一些难题。

它应该如何工作

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

我遇到的问题是消息 No lurkers around to kick 今天没有输出。

以下是我正在努力让您了解我想要实现的目标:

@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: ")

其他:
wait self.bot.say("今天没有潜伏者可以踢。:raised_hands: ")

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

如果有帮助,我们将不胜感激。

最佳答案

在这里,我们建立了一个潜伏者列表,然后决定是否踢掉他们。请注意,踢或不踢的决定只发生一次,在循环之外。

@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: ")

关于python - 等待语句不输出消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52257398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com