在用户添加反应后在新行显示昵称

Show a nickname on new line after a user add reaction

我正在尝试在用户点击反应后显示用户 Discord.Tag(或昵称),使用不和谐 API。

在我的代码中,Discord.tag 刚刚被上次点击反应的用户覆盖。用户可以±30.

这就是我想要的:

我的代码:

private async Task OnReactionAdded(Cacheable<IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
{
    var User = arg3.User.Value as SocketGuildUser;
    ulong MessageID = 843502656663715860;
    if (arg3.MessageId != MessageID) return;
    if (arg3.Emote.Name != "✅") return;

    var message = (RestUserMessage)await arg2.GetMessageAsync(MessageID);
    await message.ModifyAsync(x =>                                    // Edit message
    {
        var exampleField = new EmbedFieldBuilder()
            .WithName("New Users")
            .WithValue($"User: {arg3.User.Value} \n " +               //overwritting user
                       $"User: {arg3.User.Value} \n ");               //
        x.Embed = new EmbedBuilder()
            .AddField(exampleField)
            .Build();
    });
}

我以不同的方式解决了这个问题。这是用户添加反应的代码

private async Task OnReactionAdded(Cacheable<IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
{
     var User = arg3.User.Value as SocketGuildUser;
     if (arg3.MessageId != 843502656663715860) return;
     if (arg3.Emote.Name != "✅") return;
     var message = (RestUserMessage)await arg2.GetMessageAsync(843502656663715860);
     var newUser = message.Embeds.FirstOrDefault().Fields.FirstOrDefault().Value;
     if (newUser.Contains((arg3.User.Value).ToString())) return;
     await message.ModifyAsync(x => 
     {
          var exampleField = new EmbedFieldBuilder()
                 .WithName("New Users")
                 .WithValue($"{newUser}\n{arg3.User.Value}");
          x.Embed = new EmbedBuilder()
                  .AddField(exampleField)
                  .Build();
      });
}

还有奖励,如果用户删除反应

代码

private async Task OnReactionRemoved(Cacheable<IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
{
    if (arg3.MessageId != 843502656663715860) return;
    if (arg3.Emote.Name != "✅") return;
    var User = arg3.User.Value.ToString();
    var message = (RestUserMessage)await arg2.GetMessageAsync(843502656663715860);                                                                        
    var newUser = message.Embeds.FirstOrDefault().Fields.FirstOrDefault().Value;
    string newValue = "";
    if (newUser.Contains((arg3.User.Value).ToString()))
    {
        newValue = newUser.Replace($"\n{arg3.User.Value}", " ");
    }
    await message.ModifyAsync(x => 
    {
        var exampleField = new EmbedFieldBuilder()
                .WithName("New Users")
                .WithValue($"{newValue}");
        x.Embed = new EmbedBuilder()
                .AddField(exampleField)
                .Build();
    });
}