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'”
谢谢任何帮助。在
change_stats
将是Example
对象的属性:请看Recipes部分中的示例,在这里您可以找到cogs中任务的更多用法。在
相关问题 更多 >
编程相关推荐