Python 3.x 名称错误:名称';mag&x27;没有定义

Python 3.x 名称错误:名称';mag&x27;没有定义,python-3.x,Python 3.x,我的代码: if message.content == "pingrole": role = discord.utils.find(lambda r: r.name == "ping", mag.server.roles) await client.add_roles(member, roles) 错误是: Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\P

我的代码:

if message.content == "pingrole":
    role = discord.utils.find(lambda r: r.name == "ping", mag.server.roles)
    await client.add_roles(member, roles)
错误是:

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\PC\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "C:/Users/PC/Desktop/mylittlebotMK2.py", line 26, in on_message
    role = discord.utils.find(lambda r: r.name == "ping", mag.server.roles)
NameError: name 'mag' is not defined
我也有一个client.run命令,但想保护我的令牌。

可能会添加(在创建令牌的地方,代码中没有显示):

全球杂志

使对象在函数的本地上下文中可访问


为了消除错误“mag”必须被定义为脚本mylittlebotMK2.py的全局可访问变量。py不起作用,我也是python的新手,因此如果您能提供,我需要更多关于事情的详细信息。您需要向我们展示代码中“mag=”的设置位置(如果是),如果太长,可能使用pastebin,并且没有任何。。。你能给我一个命令的例子吗?如果你在没有基本python知识的情况下修改一些你发现的(并且已经有bug)随机脚本,应该会有。我担心如果没有完整的代码和您想要实现的想法,您将不会得到太多帮助。好的,让我编辑页面以获得完整的代码。。。我正在尝试实现一个discord机器人,它在命令发出时提供角色