NameError: имя 'ctx' не определено - PullRequest
0 голосов
/ 05 сентября 2018

Продолжайте получать эту ошибку в моей дискотеке бота cog. Я использую message.author в других Cogs просто отлично с событиями, а не командами.

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, и он также прекрасно работает в Cog в событии on_message. Он не работает, только когда я использую его внутри командной функции @ commands.command.

...