繁体   English   中英

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

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

我想制作一个基于反应行动的 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")

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

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的唯一 function 的文档。 然后我不断点击reaction.message.channel中的成员链,直到reaction .message.channel 的存在变得明显。 我告诉你这个是因为你也可以那样做。 基本上,我给了你一条鱼,并试图教你如何钓鱼。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM