我想到的目标是,我的不和谐机器人会在一段时间后将它的状态更改为我添加到列表中的随机状态。
import discord
import random
from discord.ext import commands, tasks
class Status(commands.Cog):
def __init__(self, client):
self.client = client
self.client.random_status_loop.start()
@tasks.loop(seconds=5.0)
async def random_status_loop(self):
status = [
'Value1',
'Value2',
'Value3',
'Value4',
'Value5',
'',
'Value6']
await self.client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=(random.choice(status))))
def setup(client):
client.add_cog(Status(client))我刚刚学习了一些关于这方面的教程,对于使用Python进行编程仍然是个新手。这就是我放置在一个齿轮内的东西,在主bot.py文件中这个文件工作得很好,但是当把它放入齿轮中时,它会给我以下错误: discord.ext.commands.errors.ExtensionFailed: Extension‘cogs.status’引发了一个错误: AttributeError:'Bot‘对象没有属性'random_status_loop’
是否有什么东西是我可能遗漏的,我需要添加一个特定的属性才能起作用吗?任何帮助都是非常感谢的。
发布于 2021-01-02 15:25:39
函数random_status_loop()属于Status类,而不是self.client。
试试self.random_status_loop.start()的self.client.random_status_loop_start()整数
https://stackoverflow.com/questions/65540673
复制相似问题