Discord上的反应角色.Net从命令嵌入



我想将反应角色添加到由命令创建的Embed中

我知道当我为反应角色自动发布时,它会使用客户端。ReactionAdded,但当将其添加到我的Program.cs并使用ISocketMessage Channel时,这是一个错误,不起作用。

我的命令创建一个嵌入并添加一个竖起大拇指的表情符号,我想在点击竖起大拇指的表情符号时为用户设置一个角色

using Discord;
using Discord.Net;
using Discord.WebSocket;
using Discord.Commands;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
namespace CentricXBot.Modules.Fun
{
// for commands to be available, and have the Context passed to them, we must inherit ModuleBase
public class Test : ModuleBase
{
[Command("test")]
public async Task TestComand()

{
var embed = new EmbedBuilder()
{
Title = "TestEmbed",
Description = "Test",

}.Build();
var myReaction = new Emoji("👍");
var msg =  await Context.Channel.SendMessageAsync(embed: embed);
msg.AddReactionAsync(new Emoji("👍"));

}
}
}

好的,我对此很不清楚。。我有这种结构的

{


// call ConfigureServices to create the ServiceCollection/Provider for passing around the services
using (var services = ConfigureServices())
{
// get the client and assign to client 
// you get the services via GetRequiredService<T>
var client = services.GetRequiredService<DiscordSocketClient>();
_client = client;

// setup logging and the ready event
services.GetRequiredService<LoggingService>();
services.GetRequiredService<TwitchHandler>();
// this is where we get the Token value from the configuration file, and start the bot
await client.LoginAsync(TokenType.Bot, _config["token"]);
await client.StartAsync();
await client.SetGameAsync("LPDaVinci auf Twitch", "https://twitch.tv/lpdavinci", ActivityType.Streaming);

client.ReactionAdded += ReactionAdded_Event; //No overload its underscored

// we get the CommandHandler class here and call the InitializeAsync method to start things up for the CommandHandler service
await services.GetRequiredService<CommandHandler>().InitializeAsync();
await Task.Delay(-1);
}
}
public void ReactionAdded_Event(Cacheable<IUserMessage, UInt64> message, ISocketMessageChannel channel, SocketReaction reaction)
{
// idk how to get the cached embed message to get this triggered
}```
i tried adding the client.ReactionAdded  but it cannot get the msg,
MessageCacheSize = 1000, is activated but i dont know how to get the embed Message posted by command for the reaction role

到目前为止,这是我想要做的代码,消息存储和获取ID还没有完成,我需要获取ID。如果使用embeds message.id是唯一的方法。。否则,我可以使用msg.content.contents("字符串"(作为我需要使用message.id的嵌入,但要手动获取它。。如果有人知道如何做,最好随时联系我:(再次感谢Anu6is

public async Task ReactionAdd(Cacheable<IUserMessage, ulong> message, Cacheable<IMessageChannel, ulong> channel, SocketReaction reaction)
{
if (_client.GetUser(reaction.UserId).IsBot) return;
var msg = await message.GetOrDownloadAsync();
if (msg.Id.Equals(960529258160214036)){

if (reaction.Emote.Name != "👍") return;
await (reaction.User.Value as SocketGuildUser).AddRoleAsync(913407637075394590);
_logger.LogInformation($"Rolle [{(reaction.User.Value as SocketGuildUser).Guild.GetRole(913407637075394590)}] hinzugefügt für [{reaction.User}]");
}

}
public async Task ReactionRemove(Cacheable<IUserMessage, ulong> message, Cacheable<IMessageChannel, ulong> channel, SocketReaction reaction)
{
if (_client.GetUser(reaction.UserId).IsBot) return;
var msg = await message.GetOrDownloadAsync();
if (msg.Id.Equals(960529258160214036)){

if (reaction.Emote.Name != "👍") return;
await (reaction.User.Value as SocketGuildUser).RemoveRoleAsync(913407637075394590);
_logger.LogInformation($"Rolle [{(reaction.User.Value as SocketGuildUser).Guild.GetRole(913407637075394590)}] entfernt für [{reaction.User}]");
}
}

相关内容

最新更新