AttributeError:'会员'对象没有属性'频道'



我想制作一个基于反应的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"对象没有属性"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的函数。然后我不断点击reaction中的成员链,直到reaction.message.channel明显存在为止。我告诉你这个是因为你也可以那样做。基本上,我给了你一条鱼,还试着教你如何钓鱼。

最新更新