Fix some unchecked access in the giveRole function in the reactionListener that would crash the bot if an expected value wasn't around
This commit is contained in:
parent
7cc9fc92d9
commit
fdd23ad00f
1 changed files with 4 additions and 1 deletions
|
@ -70,7 +70,10 @@ namespace Geekbot.Core.ReactionListener
|
|||
|
||||
public async void GiveRole(ISocketMessageChannel channel, SocketReaction reaction)
|
||||
{
|
||||
var roleId = _listener[reaction.MessageId][reaction.Emote];
|
||||
_listener.TryGetValue(reaction.MessageId, out var registeredReactions);
|
||||
if (registeredReactions == null) return;
|
||||
if (!registeredReactions.ContainsKey(reaction.Emote)) return;
|
||||
var roleId = registeredReactions[reaction.Emote];
|
||||
var guild = (SocketGuildChannel) channel;
|
||||
var role = guild.Guild.GetRole(roleId);
|
||||
await ((IGuildUser) reaction.User.Value).AddRoleAsync(role);
|
||||
|
|
Loading…
Reference in a new issue