【发布时间】:2021-07-28 10:37:17
【问题描述】:
我想制作一个基于反应行动的不和谐机器人,代码如下:
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事件是否在战斗命令中?
标签: python discord discord.py