我的 nextcord (python) 忽略第一个 if 语句下面的 if 语句,并且无法弄清楚为什么

发布于 2025-01-20 13:58:19 字数 1052 浏览 0 评论 0原文

抱歉,如果这是一个愚蠢的问题,但是每当我运行代码时,它都不会侦听 if 语句中的 if 语句?

@bot.command()
@commands.has_role('Moderator')
async def activity(ctx):
    days = datetime.datetime.now() - datetime.timedelta(days=7)
    print(days)
    for member in ctx.guild.members:
        for role in member.roles:
            if role.name == "Trusted Member":
                if role.name == "Exempt":
                    print("<@" + str(member.id) + "> has a perm exemption")
                elif role.name == "Temp Exempt":
                    print("<@" + str(member.id) + "> has a temp exemption, it has now been removed...")
                else:
                    counter = 0
                    channel = bot.get_channel(1)
                    async for message in channel.history(limit=None, after=days):
                        if message.author == member:
                            counter += 1
                    print("<@" + str(member.id) + "> has sent " + str(counter))

该脚本不会检查他们是否具有豁免角色,而是继续检查他们已发送的消息数量。

提前致谢。

Sorry if this is a dumb question, however whenever I'm running my code it does not listen to the if statements within the if statement?

@bot.command()
@commands.has_role('Moderator')
async def activity(ctx):
    days = datetime.datetime.now() - datetime.timedelta(days=7)
    print(days)
    for member in ctx.guild.members:
        for role in member.roles:
            if role.name == "Trusted Member":
                if role.name == "Exempt":
                    print("<@" + str(member.id) + "> has a perm exemption")
                elif role.name == "Temp Exempt":
                    print("<@" + str(member.id) + "> has a temp exemption, it has now been removed...")
                else:
                    counter = 0
                    channel = bot.get_channel(1)
                    async for message in channel.history(limit=None, after=days):
                        if message.author == member:
                            counter += 1
                    print("<@" + str(member.id) + "> has sent " + str(counter))

The script will not check if they have an exempt role and instead just proceed to check how many messages they have sent.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_畞蕅 2025-01-27 13:58:19

我在帮助Rani的帮助下找到的解决方案

@bot.command()
@commands.has_role('Moderator')
async def activity(ctx):
    days = datetime.datetime.now() - datetime.timedelta(days=7)
    for member in ctx.guild.members:
        role_names = []
        for role in member.roles:
            role_names.append(role.name)
        if "Trusted Member" in role_names:
            if "Exempt" in role_names:
                print("<@" + str(member.id) + "> has a perm exemption")
            elif "Temp Exempt" in role_names:
                print("<@" + str(member.id) + "> has a temp exemption, it has now been removed...")
            else:
                counter = 0
                channel = bot.get_channel(1)
                async for message in channel.history(limit=None, after=days):
                    if message.author == member:
                        counter += 1
                print("<@" + str(member.id) + "> has sent " + str(counter))```

Working solution I found with help thanks to Rani

@bot.command()
@commands.has_role('Moderator')
async def activity(ctx):
    days = datetime.datetime.now() - datetime.timedelta(days=7)
    for member in ctx.guild.members:
        role_names = []
        for role in member.roles:
            role_names.append(role.name)
        if "Trusted Member" in role_names:
            if "Exempt" in role_names:
                print("<@" + str(member.id) + "> has a perm exemption")
            elif "Temp Exempt" in role_names:
                print("<@" + str(member.id) + "> has a temp exemption, it has now been removed...")
            else:
                counter = 0
                channel = bot.get_channel(1)
                async for message in channel.history(limit=None, after=days):
                    if message.author == member:
                        counter += 1
                print("<@" + str(member.id) + "> has sent " + str(counter))```
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文