Discord.PY,反应角色发生错误?
Discord.PY, reaction role error occuring?
好的,我正在尝试创建一个命令,用户可以在其中执行 (prefix)requestrole discordid roleid。然后它会向某个频道发送一个嵌入的请求,某些角色可以在其中查看该频道,他们可以单击复选标记反应或 'x' 反应来接受或拒绝角色请求。
@commands.command()
async def requestrole(self, ctx, discordid, roleid):
discordid = int(discordid)
roleid = int(roleid)
userid = ctx.author.id
channel = self.bot.get_channel(FILLWITHCHANNELID)
guild = ctx.guild
user = ctx.author
role = get(guild.roles, id=roleid)
embed = discord.Embed(title="Role Request", description=f"{user} requested {role} for {userid}", color=0x00ff00)
await channel.send(embed=embed)
message = await embed.send(embed=embed)
await message.add_reaction("✅")
await message.add_reaction("❌")
@self.bot.event
async def on_reaction_add(reaction, user):
if reaction.emoji == "✅":
user = reaction.message.author
guild = reaction.message.guild
role = get(guild.roles, id=roleid)
await user.add_roles(role)
await channel.send(f"{user} has been given {role}")
elif reaction.emoji == "❌":
await reaction.message.send("Role request denied")
这是我现在收到的错误
Ignoring exception in command requestrole:
Traceback (most recent call last):
File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\name\Documents\GitHub\PRP-Bot\cogs\role_cog.py", line 31, in requestrole
message = await embed.send(embed=embed)
AttributeError: 'Embed' object has no attribute 'send'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Embed' object has no attribute 'send'
我的问题特别是导致错误的原因,以及如何正确编码以便用户基本上可以单击反应复选标记添加角色,或单击 x 删除角色。
您正在尝试向 Embed 发送消息。这不是嵌入的工作方式。您可以将消息发送到频道,但不能发送到嵌入。只需删除行 message = await embed.send(embed=embed)
就可以了
好的,我正在尝试创建一个命令,用户可以在其中执行 (prefix)requestrole discordid roleid。然后它会向某个频道发送一个嵌入的请求,某些角色可以在其中查看该频道,他们可以单击复选标记反应或 'x' 反应来接受或拒绝角色请求。
@commands.command()
async def requestrole(self, ctx, discordid, roleid):
discordid = int(discordid)
roleid = int(roleid)
userid = ctx.author.id
channel = self.bot.get_channel(FILLWITHCHANNELID)
guild = ctx.guild
user = ctx.author
role = get(guild.roles, id=roleid)
embed = discord.Embed(title="Role Request", description=f"{user} requested {role} for {userid}", color=0x00ff00)
await channel.send(embed=embed)
message = await embed.send(embed=embed)
await message.add_reaction("✅")
await message.add_reaction("❌")
@self.bot.event
async def on_reaction_add(reaction, user):
if reaction.emoji == "✅":
user = reaction.message.author
guild = reaction.message.guild
role = get(guild.roles, id=roleid)
await user.add_roles(role)
await channel.send(f"{user} has been given {role}")
elif reaction.emoji == "❌":
await reaction.message.send("Role request denied")
这是我现在收到的错误
Ignoring exception in command requestrole: Traceback (most recent call last): File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "C:\Users\name\Documents\GitHub\PRP-Bot\cogs\role_cog.py", line 31, in requestrole message = await embed.send(embed=embed) AttributeError: 'Embed' object has no attribute 'send'
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\discord\ext\commands\core.py", line 94, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Embed' object has no attribute 'send'
我的问题特别是导致错误的原因,以及如何正确编码以便用户基本上可以单击反应复选标记添加角色,或单击 x 删除角色。
您正在尝试向 Embed 发送消息。这不是嵌入的工作方式。您可以将消息发送到频道,但不能发送到嵌入。只需删除行 message = await embed.send(embed=embed)
就可以了