Skip to content

Commit

Permalink
Fixed exception at trying to re-add user to ticket that no longer exists
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Nov 7, 2021
1 parent b8103a3 commit 2331f6a
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions SupportBoi/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,19 @@ internal async Task OnMemberAdded(DiscordClient client, GuildMemberAddEventArgs

foreach (Database.Ticket ticket in ownTickets)
{
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
if (channel?.GuildId == e.Guild.Id)
try
{
await channel.AddOverwriteAsync(e.Member, Permissions.AccessChannels, Permissions.None);
DiscordEmbed message = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Green)
.WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket.");
await channel.SendMessageAsync(message);
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
if (channel?.GuildId == e.Guild.Id)
{
await channel.AddOverwriteAsync(e.Member, Permissions.AccessChannels, Permissions.None);
DiscordEmbed message = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Green)
.WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket.");
await channel.SendMessageAsync(message);
}
}
catch (Exception) { }
}
}

Expand All @@ -239,14 +243,18 @@ internal async Task OnMemberRemoved(DiscordClient client, Guild​Member​Remov
{
foreach(Database.Ticket ticket in ownTickets)
{
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
if (channel?.GuildId == e.Guild.Id)
try
{
DiscordEmbed message = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Red)
.WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server.");
await channel.SendMessageAsync(message);
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
if (channel?.GuildId == e.Guild.Id)
{
DiscordEmbed message = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Red)
.WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server.");
await channel.SendMessageAsync(message);
}
}
catch (Exception) { }
}
}

Expand All @@ -255,16 +263,21 @@ internal async Task OnMemberRemoved(DiscordClient client, Guild​Member​Remov
DiscordChannel logChannel = await client.GetChannelAsync(Config.logChannel);
if (logChannel != null)
{

foreach (Database.Ticket ticket in assignedTickets)
{
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
if (channel?.GuildId == e.Guild.Id)
try
{
DiscordEmbed message = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Red)
.WithDescription("Assigned staff member '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server: <#" + channel.Id + ">");
await logChannel.SendMessageAsync(message);
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
if (channel?.GuildId == e.Guild.Id)
{
DiscordEmbed message = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Red)
.WithDescription("Assigned staff member '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server: <#" + channel.Id + ">");
await logChannel.SendMessageAsync(message);
}
}
catch (Exception) { }
}
}
}
Expand Down

0 comments on commit 2331f6a

Please sign in to comment.