bot.get_channel()在嵌齿轮中不起作用

时间:2020-06-15 05:05:26

标签: python-3.x discord.py

这在没有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))

即使不一致,用户也无法在COG中工作。 错误:命令引发异常:AttributeError:“用户”对象没有属性“角色”

    @commands.command()
    async def userinfo(self,ctx,user:discord.User = None):
        msg = ''
        for a in user.roles:
            msg+= a.name

1 个答案:

答案 0 :(得分:0)

您尝试过

channel = await self.bot.get_channel(int(val))