Fixed a bug that would prevent a bot on the whitelist processing the message.

This commit is contained in:
Brett Hewitson 2021-12-16 20:44:11 +10:00
parent f9c6702108
commit 4aef891312
5 changed files with 59 additions and 9 deletions

View file

@ -29,8 +29,7 @@ namespace ServerManagerTool.DiscordBot.Services
private async Task OnMessageReceivedAsync(SocketMessage s)
{
// Ensure the message is from a user/bot
var msg = s as SocketUserMessage;
if (msg is null)
if (!(s is SocketUserMessage msg))
{
return;
}
@ -41,10 +40,15 @@ namespace ServerManagerTool.DiscordBot.Services
return;
}
// Tell bot to ignore itself, unless on the whitelist
if (msg.Author.IsBot && !_botWhitelist.DiscordBotWhitelists.Any(b => b.BotId.Equals(msg.Author.Id)))
// check if the author is a bot
if (msg.Author.IsBot)
{
return;
// check if bot is on the whitelist
if (!_botWhitelist.DiscordBotWhitelists.Any(b => b.BotId.Equals(msg.Author.Id.ToString())))
{
// Tell bot to ignore
return;
}
}
// Create the command context