简体   繁体   English

AttributeError: 'Member' object 没有属性 'channel'

[英]AttributeError: 'Member' object has no attribute 'channel'

i want to make a discord bot which acts based on reactions, heres the code:我想制作一个基于反应行动的 discord 机器人,代码如下:

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")

but when i run it it shows the error code AttributeError: 'Member' object has no attribute 'channel'.但是当我运行它时,它显示错误代码 AttributeError: 'Member' object has no attribute 'channel'。 How to fix it?如何解决?

The second argument of on_reaction_add is not message . on_reaction_add的第二个参数不是message It's user .user I think what you want is我想你想要的是

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

Honestly, I've never even used Discord module, and don't know anything about it.老实说,我什至从未使用过 Discord 模块,对此一无所知。 I just looked at the docs for the only function where you were trying to get a channel from the argument.我只是查看了您试图从参数中获取channel的唯一 function 的文档。 Then I kept clicking the chain of members in reaction til it became apparent that reaction.message.channel exists.然后我不断点击reaction.message.channel中的成员链,直到reaction .message.channel 的存在变得明显。 I'm telling you this because you could do that, too.我告诉你这个是因为你也可以那样做。 Basically, I gave you a fish and also trying to teach you how to fish.基本上,我给了你一条鱼,并试图教你如何钓鱼。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'str' object 没有属性 'member' 错误 - AttributeError: 'str' object has no attribute 'member' Error AttributeError: 'Member' object 没有属性 'emoji' - AttributeError: 'Member' object has no attribute 'emoji' AttributeError: 'Member' object 没有属性 'client' - AttributeError: 'Member' object has no attribute 'client' Discord.py“AttributeError:‘str’对象没有‘channel’属性” - Discord.py "AttributeError: 'str' object has no attribute 'channel'" AttributeError: 'NoneType' 对象没有属性 'channel' discord.py - AttributeError: 'NoneType' object has no attribute 'channel' discord.py 命令引发异常:AttributeError: 'str' object has no attribute 'channel' - Command raised an exception: AttributeError: 'str' object has no attribute 'channel' Python错误:AttributeError:类型对象'MyClass'没有属性'channel' - Python error: AttributeError: type object 'MyClass' has no attribute 'channel' paramiko频道AttributeError:'NoneType'对象没有属性'recv' - paramiko channel AttributeError: 'NoneType' object has no attribute 'recv' AttributeError:“列表”对象没有属性“通道” discord.py - AttributeError: 'list' object has no attribute 'channel' discord.py Python-can:AttributeError:“list”对象没有属性“channel” - Python-can: AttributeError: 'list' object has no attribute 'channel'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM