【问题标题】:The role is not issued when clicking on the reaction点击反应时角色不发出
【发布时间】:2021-02-12 16:04:34
【问题描述】:

我的异常说 user = null 但我不明白为什么? UserId 在调试器中传递

 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);
                    }
                }
            }

【问题讨论】:

    标签: c# discord.net


    【解决方案1】:

    用户为 null 可能是由于最近对 Discrod API 的更改导致的,请参阅 this。更改导致Guild.User 信息未正确下载。

    1. 首先要检查的是用户是否在Context.Guild 上分配(您还可以验证您的Discord 服务器中的用户在Context.Guild.Users 上是否相同)。
    2. 其次,您需要在 Discord Bot 上启用此功能

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 1970-01-01
      • 2021-02-07
      相关资源
      最近更新 更多