NameError:名称'ctx'未定义

时间:2018-09-05 02:09:39

标签: python python-3.x discord discord.py

请继续在我的Discord机器人齿轮中收到此错误。我在其他嵌齿轮中使用message.author只是对事件而不是命令很好。

async def on_member_join(member):
    with open('profiles.json', 'r') as f:
        profiles = json.load(f)

    await update_profile(profiles, member)

    with open('profiles.json', 'w') as f:
            json.dump(profiles, f, indent=2)

@commands.command(name='my', pass_context=True)
async def my(self, ctx):

    with open('profiles.json', 'r') as x:
        profiles = json.load(x)

    await self.update_profile(profiles, ctx.message.author)

    with open('profiles.json', 'w') as x:
        json.dump(profiles, x, indent=2)


async def update_profile(self, user, message):
        profile_params = {'Xbox Live': 'xbl', 'PSN': 'psn', 'Steam ID': 'stm','Nintendo Friend Code': 'nfc'}
        msg = ctx.message
        bmsg = msg[4:7]
        emsg = msg[8:]
        if not user.name in users and not user.bot:
            do some stuff 

这是我遇到的错误,我已经尝试了许多解决方法,但找不到任何可以解决此问题的方法

     Traceback (most recent call last):
  File "C:\Users\Erik\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "D:\Discord Bot\profiles.py", line 28, in my
    await self.update_profile(profiles, ctx.message.author)
  File "D:\Discord Bot\profiles.py", line 36, in update_profile
    msg = ctx.message
NameError: name 'ctx' is not defined

我已经尝试了许多解决方案来寻找类似的问题。我注意到它在主py文件中运行良好,并且在on_message事件中的嵌齿轮中也运行良好。仅当我在@ commands.command命令功能中使用它时,它才行不通。

0 个答案:

没有答案