Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Discord.py 命令引发异常:AttributeError:';非类型';对象没有属性';发送';_Discord.py - Fatal编程技术网

Discord.py 命令引发异常:AttributeError:';非类型';对象没有属性';发送';

Discord.py 命令引发异常:AttributeError:';非类型';对象没有属性';发送';,discord.py,Discord.py,我试图发出一个命令,将消息发送到指定的通道,并得到以下错误 命令引发了异常:AttributeError:'NoneType'对象没有属性'send' @client.command(name="chmsg") async def _chmsg(ctx): def check(msg): return msg.author == ctx.author and \ msg.channel == ctx.channel

我试图发出一个命令,将消息发送到指定的通道,并得到以下错误

命令引发了异常:AttributeError:'NoneType'对象没有属性'send'

@client.command(name="chmsg")
async def _chmsg(ctx):

    def check(msg):
        return msg.author == ctx.author and \
               msg.channel == ctx.channel

    await ctx.send("Message")
    mestoc = await client.wait_for("message", check=check)
    await ctx.send("Channel id")
    chasend = await client.wait_for("message", check=check)
    mestoch = str(mestoc.content)
    cha = str(chasend.content)
    channel = client.get_channel(cha)
    await channel.send(f"{mestoch}")
  • 您不必将
    mestoc.content
    转换为字符串,因为它已经是字符串了

  • 您需要
    cha
    作为一个整数,而不是字符串,这样才能获得频道

  • 因此,修改后的代码如下所示

    @client.command(name="chmsg")
    async def _chmsg(ctx):
    
        def check(msg):
            return msg.author == ctx.author and \
                   msg.channel == ctx.channel
    
        await ctx.send("Message")
        mestoc = await client.wait_for("message", check=check)
        await ctx.send("Channel ID")
        chasend = await client.wait_for("message", check=check)
        mestoch = mestoc.content
        cha = int(chasend.content)
        channel = client.get_channel(cha)
        await channel.send(f"{mestoch}")
    

    对于这么简单的命令来说,这看起来太复杂了。您只是在寻找一个命令,该命令将某些内容发送到某个通道吗?