问题
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.
- 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 theContext.Guild.Users
). - 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