程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了AttributeError: 'Member' 对象没有属性 'channel'大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_674_0@如何解决AttributeError: 'Member' 对象没有属性 'chAnnel'? 开发过程中遇到AttributeError: 'Member' 对象没有属性 'chAnnel'的问题如何解决?下面主要结合日常开发的经验,给出你关于AttributeError: 'Member' 对象没有属性 'chAnnel'的解决方法建议,希望对你解决AttributeError: 'Member' 对象没有属性 'chAnnel'有所启发或帮助;

我想制作一个基于反应的不和谐机器人,代码如下:

import discord
    from discord.ext import commands
    import random
    pershealth=50
    enhealth=75
    clIEnt= commands.bot(command_prefix='!')
    @clIEnt.event
    async def on_ready():
        await clIEnt.change_presence(activity=discord.Game("fighTing"))
        print("Works")
    @clIEnt.command()
    async def fight(ctX):
        options=["no","yes"]
        choice=random.choice(options)
        if(choice=="no"):
            await ctx.send("no monsters where found")
        else:
            msg=await ctx.send("Monster found,do you wAnna fight it?")
            await msg.add_reaction(emoji=u"\U0001F44D")
            await msg.add_reaction(emoji=u"\U0001F44E")
            @clIEnt.event
            async def on_reaction_add(reaction,messagE):
                if reaction.emoji=="?":
                    chAnnel=message.chAnnel.ID
                    msg=await chAnnel.send("test")
    clIEnt.run("code")

但是当我运行它时,它显示错误代码 AttributeError: 'Member' object has no attribute 'chAnnel'。如何解决?

@H_674_0@解决方法

on_reaction_add 的第二个参数不是 message。它是user。我想你想要的是

@client.event
async def on_reaction_add(reaction,user):
    if reaction.emoji=="?":
        chAnnel=reaction.message.chAnnel.id
        msg=await chAnnel.send("test")

老实说,我从未使用过 Discord 模块,对此一无所知。我只是查看了您试图从参数中获取 chAnnel 的唯一函数的文档。然后我一直点击 reaction 中的成员链,直到很明显 reaction.message.chAnnel 存在。我告诉你这个是因为你也可以这样做。基本上,我给了你一条鱼,并试图教你如何钓鱼。

大佬总结

以上是大佬教程为你收集整理的AttributeError: 'Member' 对象没有属性 'channel'全部内容,希望文章能够帮你解决AttributeError: 'Member' 对象没有属性 'channel'所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。