如何解决如何在discord.py的嵌齿轮中使用客户端?
我正在尝试让自己的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))
解决方法
创建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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。