为什么我无法在Discord.Net C#中删除反应

时间:2018-10-27 10:03:28

标签: c# discord discord.net

我无法删除Discord中的反应!使用Discord.Net API 这是我的代码。当我尝试删除反应时,它执行NullRefrenceException!但是我不知道如何解决这个问题!

public static async Task AddedReactEvent(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
    {
        var rolePC = ((ITextChannel)channel).Guild.GetRole(Secrets.PCRoleID);
        var rolePS4 = ((ITextChannel)channel).Guild.GetRole(Secrets.PS4RoleId);
        var roleXBox = ((ITextChannel)channel).Guild.GetRole(Secrets.XboxRoleID);
        var user = reaction.User.Value as SocketGuildUser;


        if (channel.Id == Secrets.RoleChannel)
        {
            if (user.Roles.Contains(rolePC) || user.Roles.Contains(rolePS4) || user.Roles.Contains(roleXBox))
            {
                try{
                    await message.Value.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                }
                catch (NullReferenceException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);

                }
                await (reaction.User.Value as IGuildUser).SendMessageAsync("", false, Webhooks.havePlattform());
            }

0 个答案:

没有答案