Python (discord py)我无法引用到服务器
当我使用Python (discord py)我无法引用到服务器,python,discord,discord.py,Python,Discord,Discord.py,当我使用ctx.guild.roles时,它说如果消息属性是第一个,我就没有必需的ctx属性,如果消息属性是第一个,那么消息属性就会丢失 我尝试使用server=client.get#u server(#server id#)) 控制台显示“'Bot'对象没有'get_server'属性”您必须这样做: light=True @客户端事件 异步def on_消息(消息): 全球光 如果message.content==“@lighton”: 轻=真 role=discord.utils.get(
ctx.guild.roles
时,它说如果消息属性是第一个,我就没有必需的ctx属性,如果消息属性是第一个,那么消息属性就会丢失
我尝试使用server=client.get#u server(#server id#))
控制台显示“'Bot'对象没有'get_server'属性”您必须这样做:
light=True
@客户端事件
异步def on_消息(消息):
全球光
如果message.content==“@lighton”:
轻=真
role=discord.utils.get(message.guild.roles,name=“Face”)
轻时:
等待角色。编辑(颜色=0xF7B0)
等待asyncio.sleep(3)
等待角色编辑(颜色=0xD36D6D)
等待asyncio.sleep(3)
elif message.content==“@lightoff”:
光=假
您的代码中还有一些错误,我冒昧地修复了这些错误。您必须这样做:
light=True
@客户端事件
异步def on_消息(消息):
全球光
如果message.content==“@lighton”:
轻=真
role=discord.utils.get(message.guild.roles,name=“Face”)
轻时:
等待角色。编辑(颜色=0xF7B0)
等待asyncio.sleep(3)
等待角色编辑(颜色=0xD36D6D)
等待asyncio.sleep(3)
elif message.content==“@lightoff”:
光=假
您的代码中还有一些错误,我冒昧地修复了这些错误。如果队列未满,我会建议进行编辑,但是
ctx
应该是消息
。这并不重要,但它是一个discord.Message
对象,而不是discord.ext.commands.Context
对象。@Makonede我已经更新了它。如果队列没有满,我会建议编辑,但ctx
应该是Message
。这并不重要,但它是一个discord.Message
对象,而不是discord.ext.commands.Context
对象。@Makonede我已经更新了它。
@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