不和.py任务.循环用于更改cog不工作的状态

2024-04-29 15:33:45 发布

您现在位置:Python中文网/ 问答频道 /正文

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, context, amount=5):
        await context.channel.purge(limit=amount)

def setup(dBot):
    dBot.add_cog(Example(dBot))

这是上面的cog文件中的代码,其中的任务不能正常工作,除此之外其他一切都可以正常工作。在

我一直得到的错误是“AttributeError:'Bot'object没有属性'change'u stats'”

谢谢任何帮助。在


Tags: fromimportselfasyncdefstatsstatuscontext