Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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 discord.py on_raw_reaction_remove(有效负载)将用户id传递为none_Python_Heroku_Discord_Ibm Cloud_Discord.py - Fatal编程技术网

Python discord.py on_raw_reaction_remove(有效负载)将用户id传递为none

Python discord.py on_raw_reaction_remove(有效负载)将用户id传递为none,python,heroku,discord,ibm-cloud,discord.py,Python,Heroku,Discord,Ibm Cloud,Discord.py,我编写了一个脚本,用于在服务器成员使用某个表情符号做出反应时分配角色,但在Heroku或ibm cloud中托管代码时,用户id的值为none 具体地说,当使用raw\u reaction\u remove()上的负载时,似乎member=guild.get\u member(payload.user\u id)正在向成员变量分配none 使用on\u raw\u reaction\u add()添加角色的效果与预期一致 #import discord lib import discord #i

我编写了一个脚本,用于在服务器成员使用某个表情符号做出反应时分配角色,但在Heroku或ibm cloud中托管代码时,用户id的值为none

具体地说,当使用raw\u reaction\u remove()上的
负载时,似乎
member=guild.get\u member(payload.user\u id)
正在向成员变量分配none

使用
on\u raw\u reaction\u add()
添加角色的效果与预期一致

#import discord lib
import discord
#import commands from discord lib
from discord.ext import commands

#set client variable to use disocrd commands
client = commands.Bot(command_prefix = ".")

#start event and check Bot is ready
@client.event
async def on_ready():
    print("Bot is ready.")

#upon detecting a reaction event assign the role which matches the reaction emoji
#see https://discordpy.readthedocs.io/en/latest/api.html?#rawreactionactionevent
@client.event
async def on_raw_reaction_add(payload):
    message_id = payload.message_id

    #check if the message id matches the message id of the "assign your role!" message in discord
    if message_id == 123456789:
        #get the server name from the payload
        guild = client.get_guild(payload.guild_id)
        #get the member name from the payload
        member=(payload.member)

        #Debugging
        Post_Message = "Add(1/3) - Message ID matches."
        Post_Message = Post_Message+"'"+str(guild)+"'"+" is the Guild ID."
        Post_Message = Post_Message+"'"+str(member)+"'"+" is the Member ID."
        print(str(Post_Message))

        #if the name of the reaction emoji is "League" theen assign the "League bois discord role
        if payload.emoji.name == "League":
            role = discord.utils.get(guild.roles, name="League bois")
        else:
        #set role variable to the name of the reaction emoji
            role = discord.utils.get(guild.roles, name=payload.emoji.name)

        if role is not None:
            
            #debugging
            print("Add(2/3) - Attempting to assign Role...")
            
            if member is not None:
                #add the role
                await member.add_roles(role)
                #Debugging
                print("Add(3/3) - Role has been assigned.")
            else:
                print("Member not found.")
                print("Member returned is: "+str(member))
        else:
            print("Role not found.")
            print("Role Returned is: "+str(role))
但是在Heroku或ibmcloud中托管时,使用\u raw\u reaction\u remove()上的
删除角色不起作用。在本地运行时,它可以成功运行

#upon detecting a a reaction emoji being removed, remove the appropriate role on discord
@client.event
async def on_raw_reaction_remove(payload):
    message_id = payload.message_id

    # check if the message id matches the message id of the "assign your role!" message in discord
    if message_id == 123456789:
        #get the server name from the payload
        guild = client.get_guild(payload.guild_id)
        # payload.member is not availible for REACTION_REMOVE event type
        member = guild.get_member(payload.user_id)

        #Debugging
        Post_Message = "Remove(1/3) - Message ID matches."
        Post_Message = Post_Message+"'"+str(guild)+"'"+" is the Guild ID."
        Post_Message = Post_Message+"'"+str(member)+"'"+" is the Member ID."
        print(str(Post_Message))

        # if the name of the reaction emoji is "League" theen assign the "League bois discord role
        if payload.emoji.name == "League":
            role = discord.utils.get(guild.roles, name="League bois")

        else:
            # set role variable to the name of the reaction emoji
            role = discord.utils.get(guild.roles, name=payload.emoji.name)

        if role is not None:
            
                    
            #Debugging
            print("Remove(2/3) - Attempting to remove Role...")
            

            if member is not None:
                #remove the role
                await member.remove_roles(role)
                #Debugging
                print("Remove(3/3) - Role has been removed.")
            else:
                print("Member not found.")
                print("Member returned is: "+str(member))
        else:
            print("Role not found.")
            print("Role Returned is: "+str(role))

#bot token goes here
client.run("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
如果我添加然后删除一个反应,我会得到以下结果

Add(1/3) - Message ID matches.'test big XD haha lol' is the Guild ID.'daz#6949' is the Member ID.
Add(2/3) - Attempting to assign Role...
Add(3/3) - Role has been assigned.
Remove(1/3) - Message ID matches.'test big XD haha lol' is the Guild ID.'daz#6949' is the Member ID.
Remove(2/3) - Attempting to remove Role...
Remove(3/3) - Role has been removed.
但IBM云和Heroku中的这一点

APP/PROC/WEB    0   Add(1/3) - Message ID matches.'test server' is the Guild ID.'daz#6949' is the Member ID.    Sep 30, 2020, 9:55:07 PM
APP/PROC/WEB    0   Add(2/3) - Attempting to assign Role... Sep 30, 2020, 9:55:07 PM
APP/PROC/WEB    0   Add(3/3) - Role has been assigned.  Sep 30, 2020, 9:55:07 PM
APP/PROC/WEB    0   Remove(1/3) - Message ID matches.'test server' is the Guild ID.'None' is the Member ID. Sep 30, 2020, 9:55:08 PM
APP/PROC/WEB    0   Remove(2/3) - Attempting to remove Role...  Sep 30, 2020, 9:55:08 PM
APP/PROC/WEB    0   Member not found.   Sep 30, 2020, 9:55:08 PM
APP/PROC/WEB    0   Member returned is: None    Sep 30, 2020, 9:55:08 PM
有什么想法吗?

derw是正确的

我在本地安装了discord.py 1.4.1。 运行py-3-mpip安装-U discord.py并安装1.5.0。安装后,我的结果在本地和远程(IBM/Heroku)之间是一致的。 按照derw的回答,在Discord开发者门户上启用特权网关意图(状态意图和服务器成员意图),然后替换此

client = commands.Bot(command_prefix = ".")
用这个

intents = discord.Intents.all()
client = discord.Client(intents=intents)
谢谢你,德鲁

derw是正确的

我在本地安装了discord.py 1.4.1。 运行py-3-mpip安装-U discord.py并安装1.5.0。安装后,我的结果在本地和远程(IBM/Heroku)之间是一致的。 按照derw的回答,在Discord开发者门户上启用特权网关意图(状态意图和服务器成员意图),然后替换此

client = commands.Bot(command_prefix = ".")
用这个

intents = discord.Intents.all()
client = discord.Client(intents=intents)

谢谢你,德鲁

你在使用discord.py 1.5.0吗?我打赌你已经在本地安装了1.4.x,heroku正在推出最新版本1.5。您需要将discord.py冻结到1.4.2版,或者如果您想使用1.5,请参阅我关于网关意图的答案。@derw您是100%正确的。我在本地安装了1.4.1。安装了1.5.0并从Heroku/IBM复制了结果。在你的链接中跟随你的答案,现在开始工作。谢谢你在使用discord.py 1.5.0吗?我打赌你已经在本地安装了1.4.x,heroku正在推出最新版本1.5。您需要将discord.py冻结到1.4.2版,或者如果您想使用1.5,请参阅我关于网关意图的答案。@derw您是100%正确的。我在本地安装了1.4.1。安装了1.5.0并从Heroku/IBM复制了结果。在你的链接中跟随你的答案,现在开始工作。谢谢