Python 名称';我的任务';没有定义
我需要帮助来解决这个错误Python 名称';我的任务';没有定义,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,我需要帮助来解决这个错误 import discord import os import asyncio from datetime import datetime from discord.ext import commands from discord.ext.commands import errors from discord.ext import tasks from utils import default from threading import Thread from uti
import discord
import os
import asyncio
from datetime import datetime
from discord.ext import commands
from discord.ext.commands import errors
from discord.ext import tasks
from utils import default
from threading import Thread
from utils import permissions
class Presence(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.config = default.config()
@tasks.loop()
async def presence(self, presence):
await self.bot.change_presence(activity=discord.Game(name='1'))
await asyncio.sleep(1)
await self.bot.change_presence(activity=discord.Game(name='2'))
await asyncio.sleep(30)
@commands.command()
@commands.check(permissions.is_owner)
async def start(self, ctx):
"""Start's the Loop"""
self.bot.loop.create_task(my_task())
def setup(bot):
bot.add_cog(Presence(bot))
它给了我以下错误:
line 30, in start
self.bot.loop.create_task(presence())
NameError: name 'presence' is not defined
我怎样才能解决这个问题?
对于上下文:该代码应该更改Bot的状态。但是无法确定如何修复错误。您的错误消息表明您在此处提供的代码与实际引发错误的代码不同(
create\u task(presence())
vs.create\u task(my\u task())
)。请确保您已将代码包含在此处,以便其他人更容易帮助您。self.bot.loop.create_task(self.presence())
self.presence()?由于缺少代码,此问题无法回答,因此应关闭