The role is not issued when clicking on the reaction

梦想的初衷 提交于 2021-01-01 20:38:00

问题


My exception says that user = null but I don't understand why? UserId is passed in the debugger

 private async Task ReactionAdd(Cacheable<IUserMessage, ulong> cache, ISocketMessageChannel socketMessageChannel, SocketReaction reaction)
            {
                if (reaction.MessageId == 771361839917170748)
                {
                    var emote = Emote.Parse("<:NepSmug:740928682310500412>").ToString();
    
                    if (reaction.Emote.ToString() == emote)
                    {
                        var sockettextChannel = socketMessageChannel as SocketTextChannel; 
                        
                            ulong roleid = 741342300499738715;
    
                            var role = sockettextChannel.Guild.GetRole(roleid);
                            var user = sockettextChannel.Guild.GetUser(reaction.UserId);
    
                            await user.AddRoleAsync(role);
                    }
                }
            }

回答1:


The user is null might caused by recent change on the Discrod API refer to this. The changes caused the Guild.User info is not downloaded properly.

  1. First thing to check is if the User is assigned on Context.Guild or not (You can also verify if the user in your Discord server is equal on the Context.Guild.Users).
  2. Second you need to enable this feature on your Discord Bot


来源:https://stackoverflow.com/questions/64604209/the-role-is-not-issued-when-clicking-on-the-reaction

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!