[英]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.