我需要一个表情符号作为反应角色的表情符号对象,但无论我做什么我都会得到错误
discord.ext.commands.errors.PartialEmojiConversionFailure:无法将“”转换为 PartialEmoji。
如果我使用 discord.PartialEmoji 或
discord.ext.commands.errors.EmojiNotFound:找不到表情符号“”。
如果我使用 discord.Eomji。
发生这些错误的示例代码
@commands.command()
async def test(self,ctx,emoji: discord.Emoji = None):
await ctx.send(emoji)
编辑:
首先应该像这样创建反应角色:
@commands.command()
async def reactionrole(self,ctx,msgid: int = None,emoji: discord.Emoji = None , role: discord.Role = None ):
if msgid is None:
await ctx.send('Use the following template to create reactionroles (ex. treactionrole <#messageid> <emoji> <@role>)')
elif emoji is None:
await ctx.send('Use the following template to create reactionroles (ex. treactionrole <#messageid> <emoji> <@role>)')
elif role is None:
await ctx.send('Use the following template to create reactionroles (ex. treactionrole <#messageid> <emoji> <@role>)')
else:
if ctx.message.author.guild_permissions.manage_roles:
db = sqlite3.connect("db.sqlite")
cursor = db.cursor()
sql = ("INSERT INTO reaction_role(message_id,emoji,role) VALUES(?,?,?)")
val = (msgid,emoji,str(role))
msg = await ctx.channel.fetch_message(int(msgid))
await msg.add_reaction(emoji)
cursor.execute(sql,val)
db.commit()
cursor.close()
db.close()
else:
await ctx.author.send('You dont have the permission to use reactionroles on this Server!')
然后,如果发生反应,一种方法应该从数据库中获取消息,其中 msgid 和表情符号与反应的相同,如下所示:
async def reaction_roles_role(msgid,emoji):
db = sqlite3.connect("db.sqlite")
cursor = db.cursor()
cursor.execute(f"SELECT role FROM reaction_role WHERE message_id = {msgid} and emoji = {emoji}")
result = cursor.fetchone()
return result