我正在尝试让自己的bot在“ on_ready.py”嵌齿轮中具有一个状态。因此,当它联机时,状态会切换为空闲状态,并且在机器人配置文件的“播放”部分会显示命令前缀。
这是我当前的代码:
@commands.Cog.listener()
async def on_ready(self):
print('Bot is online.')
我正在尝试实现这一点:
@commands.Cog.listener()
async def on_ready(self):
await client.change presence(status=discord.Status.idle, activity=discord.Game('f.'))
print('Bot is online.')
我是新来的,因此不胜感激。
编辑:这是完整齿轮的代码:
import discord
from discord.ext import commands
class OnReady(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
await client.change presence(status=discord.Status.idle, activity=discord.Game('using f.'))
print('Bot is online.')
def setup(client):
client.add_cog(OnReady(client))
答案 0 :(得分:0)
创建OnReady
类时,您正在使用self.bot
,因此请使用它代替on_ready
。您也不需要将任何内容传递给async def on_ready(self):
事件,因此它变为import discord
from discord.ext import commands
class OnReady(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
await self.client.change_presence(status=discord.Status.idle, activity=discord.Game('using f.'))
print('Bot is online.')
def setup(client):
client.add_cog(OnReady(client))
left join