Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用on_raw_reaction_add in discord.py?_Python_Discord.py - Fatal编程技术网

Python 如何使用on_raw_reaction_add in discord.py?

Python 如何使用on_raw_reaction_add in discord.py?,python,discord.py,Python,Discord.py,好的,我有一个程序,一个票务系统。它将票据创建消息ID记录在JSON中,这样,如果程序重新启动,它可以继续检查是否添加了新的反应。但是我发现消息必须加载到机器人的缓存中,但是一旦它重新启动,它就不在那里了。所以我在原始反应添加上找到了。有人能给我解释一下这是如何工作的,也许可以对我的代码做一些修改。另外,我已经试过了,但是我删除了代码来尝试其他的东西,现在我无法恢复。但是我遇到了这个错误,我的bot拥有管理员权限:discord.errors.probled:403-probled(错误代码:5

好的,我有一个程序,一个票务系统。它将票据创建消息ID记录在JSON中,这样,如果程序重新启动,它可以继续检查是否添加了新的反应。但是我发现消息必须加载到机器人的缓存中,但是一旦它重新启动,它就不在那里了。所以我在原始反应添加上找到了
。有人能给我解释一下这是如何工作的,也许可以对我的代码做一些修改。另外,我已经试过了,但是我删除了代码来尝试其他的东西,现在我无法恢复。但是我遇到了这个错误,我的bot拥有管理员权限:
discord.errors.probled:403-probled(错误代码:50001):缺少访问权限
。请帮忙

代码:

来自discord.ext导入命令
从discord.ext导入任务
导入异步
进口不和
导入json
导入日期时间
类TicketSystem(commands.Cog):
def uuu init uuuu(自我,机器人):
self.bot=bot
异步def read_json_to_dict(self,json_文件名,通道):
json_dict={}
尝试:
以open(f“json/{json_file_name}”,“r”)作为json_文件:
json_dict=json.load(json_文件)
除:
embed_message=discord.embed(title=“Error:JSON”,description=“请在Nexus Developments discord中创建支持票证以解决此问题-https://discord.gg/YmdugDf,color=discord.color.color.red()
嵌入消息。设置页脚(text=“由Nexus Developments创建-https://discord.gg/YmdugDf,图标\ url=“https://i.imgur.com/MRBsIpe.png")
等待通道发送(嵌入=嵌入消息)
返回json_dict
异步def检查\u创建\u票据\u反应(自我、反应、用户):
create_ticket_msgs_dict=wait self.read_json_to_dict(“create_ticket_msgs_ids.json”,reaction.message.channel)
如果create_ticket_msgs_dict.keys()中的str(reaction.message.id):
如果str(reaction.emoji)=“作为
payload
参数传递,而不是
reaction
User
对象。您必须使用
payload
属性的ID或检索它们所代表的对象


至于您的错误,如果没有完整的回溯和相关的上下文,就无法判断问题是什么。

下面是一个从反应添加上的
重写到反应添加上的
的示例

@commands.Cog.listener()
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
    channel = self.bot.get_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    user = self.bot.get_user(payload.user_id)
    if not user:
        user = await self.bot.fetch_user(payload.user_id)
    # instead of reaction we should use payload.emoji
    # for example:
    await message.remove_reaction(payload.emoji, user)
将成为


如果有人希望在不做任何修改的情况下,让他们的on\u reaction\u add事件保持相同的工作状态,那么您可以得到如下反应和用户

@bot.event
原始反应添加上的异步def(有效负载):
message=wait bot.get\u通道(payload.channel\u id)。fetch\u通道(payload.message\u id)

reaction=discord.utils.get(message.reactions,emoji=“感谢您所做的一切帮助。
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
    channel = self.bot.get_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    user = self.bot.get_user(payload.user_id)
    if not user:
        user = await self.bot.fetch_user(payload.user_id)
    # instead of reaction we should use payload.emoji
    # for example:
    await message.remove_reaction(payload.emoji, user)