【发布时间】:2020-06-15 13:15:16
【问题描述】:
这在没有 COG 的情况下可以完美运行,但在 COG 中它不起作用并产生以下错误: NameError: 名称 'bot' 未定义
import discord
from discord.ext import commands
class channelinfo(commands.Cog):
#@commands.Cog.listener() [EVENT]
#@commands.command() [COMMAND]
def init(self, bot):
self.bot = bot
@commands.command()
async def channelinfo(self,ctx,*,val:str = None):
val = val.replace('<','')
val = val.replace('>','')
val = val.replace('#','')
print(val)
channel = await bot.get_channel(int(val))
即使是 discord.User 也不在 COG 中工作。 错误:命令引发异常:AttributeError:“用户”对象没有属性“角色”
@commands.command()
async def userinfo(self,ctx,user:discord.User = None):
msg = ''
for a in user.roles:
msg+= a.name
【问题讨论】:
标签: python-3.x discord.py