不显示discord.py的更新角色

时间:2020-09-07 14:15:25

标签: python discord.py

我已经尝试过很多次才能使它生效。我相信我使用的逻辑是可行的。我试图在控制台中打印出角色名称,但是它与我设置的角色不是最新的。我当时在不和谐的服务器中发送消息,但是为了测试,我只是将它们发送到终端。该程序应该在有人加入“ 1”角色时发送消息。

import discord, os, time
from dotenv import load_dotenv
from discord.ext import tasks, commands

load_dotenv()
_token = os.getenv('_token')
_server = os.getenv('_server')



found = False
_break = False
client = discord.Client()


@client.event
async def on_ready():
    await client.wait_until_ready()
    _channel = client.get_channel(int(1234567890))
    print(f"RoleCheck has connected to {client.guilds[0].name}")#await _channel.send(f"RoleCheck has connected to {client.guilds[0].name}")
    while True:
        BeforeRole = []
        AfterRole = []
        for member in client.guilds[0].members:
            for role in member.roles:
                if role.name == "1":
                    BeforeRole.append(member.name)


        time.sleep(10)
        for member in client.guilds[0].members:
            for role in member.roles:
                print(f"After: {role.name, member.name}")
                if role.name == "1":
                    AfterRole.append(member.name)

        if len(BeforeRole) < len(AfterRole):
            for name in BeforeRole:
                if _break:
                    break
                for _name in AfterRole:
                    if name !=_name:
                        print(f"{_name} has joined rank 1!")
                        break
                        found = True
                        _break = True
                    elif name == _name:
                        print("We are good")
                if _break:
                    break
            _break = False
            if not found:
                print(f"{_name[-1]} has joined rank 1!")
                found = True
        print(BeforeRole, AfterRole)
client.run(_token)

0 个答案:

没有答案