import discord
from discord.ext import commands,tasks
from itertools import cycle
status = cycle(['status 1','status 2','status 3'])
class Example(commands.Cog):
def __init__(self,dBot):
self.dBot = dBot
self.dBot.change_stats.start()
#EVENTS
@commands.Cog.listener()
async def on_member_join(self,context,member):
await context.send(f'Member {member.mention} has joined!')
#TASKS
@tasks.loop(seconds=10.0)
async def change_stats(self):
await self.dBot.change_presence(activity=discord.Game(next(status)))
#COMMANDS
@commands.command()
async def ping(self,context):
await context.send("Pong!")
@commands.command()
async def clear(self,amount=5):
await context.channel.purge(limit=amount)
def setup(dBot):
dBot.add_cog(Example(dBot))
这是上面cog文件中的代码,其中任务无法正常运行,除此之外,其他所有工作都很好。
我一直收到的错误是“ AttributeError:'Bot'对象没有属性'change_stats'”
感谢您的帮助。