【问题标题】:(discord py) I cant reffer to the server(discord py) 我无法引用服务器
【发布时间】:2021-04-11 19:20:18
【问题描述】:

当我使用ctx.guild.roles 时,它说我没有必需的 ctx 属性如果消息属性是第一个并且消息属性丢失如果 ctx 是第一个。 p>

@client.event
async def on_message(message, ctx):
    if message.content == "!lighton":
        light = True
        role = discord.utils.get(ctx.guild.roles, name="Face")
        while light:
            await client.edit_role(server=server, role=role, colour=0xF7B0B0)
            asyncio.sleep(3)
            await client.edit_role(server=server, role=role, colour=0xD36D6D)
            asyncio.sleep(3)

    elif message.content == "!lightoff":
        light = False

我尝试使用server = client.get_server(#server id#) 控制台显示“‘Bot’对象没有属性‘get_server’”

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    你必须这样做:

    light = True
    
    @client.event
    async def on_message(message):
        global light
        if message.content == '@lighton':
            light = True
            role = discord.utils.get(message.guild.roles, name = "Face")
            while light:
                await role.edit(colour = 0xF7B0B0)
                await asyncio.sleep(3)
                await role.edit(colour = 0xD36D6D)
                await asyncio.sleep(3)
        elif message.content == '@lightoff':
            light = False
    

    我冒昧地修复了您的代码中的其他一些错误。

    【讨论】:

    • 如果队列未满,我会建议进行编辑,但 ctx 应该是 message。没关系,但它是 discord.Message 对象,而不是 discord.ext.commands.Context 对象。
    猜你喜欢
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 2021-04-20
    • 2021-04-15
    • 2020-11-24
    • 2020-10-26
    • 1970-01-01
    • 2021-04-20
    相关资源
    最近更新 更多