Ich versuche, den folgenden Code von 5 auf 3.5 zu demigrieren und erhalte diesen Fehler:
CS1513: Zeile 203: } erwartet
der Fehler, wenn auf die zweite geschweifte Klammer dieses Teils verwiesen wird
catch //(Exception ex)
{
//DClient.Error(ex); }
der folgenden Methode und ich kann nicht herausfinden, warum diese Meldung angezeigt wird. es ist noch nicht in einem sln für VS und ich bin mir ehrlich gesagt nicht sicher, wie ich das machen soll oder ob mir das überhaupt die richtige "vorgeschlagene Lösung" geben würde, die ich beheben müsste
public void Invoke(MessageCreateEventArgs e)
{
try
{
if (e == null ||
!e.Message.Content[0].Equals(CommandPrefix))
return;
List<string> parameters = Split(e.Message.Content);
if (parameters == null)
parameters = new List<string>();
string command;
if (parameters.Count == 0)
command = e.Message.Content;
else
command = parameters[0];
command = command.TrimStart(CommandPrefix);
AccessLevel access = DClient.UserManager.GetAccessLevel(e.Author.Id);
//Return when command channel is set, we are outside of it and have accesslevel vip or lower
//Return when we cannot find the command itself
//Return when the command is disabled
if ((e.Guild!= null && access <= AccessLevel.VIP && DClient.Settings.CommandChannelId!= 0 && DClient.Settings.CommandChannelId!= e.Channel.Id) ||
!_commands.TryGetValue(command.ToLower(), out ICommand cmd))
return;
else if (cmd.IsDisabled)
{
e.Channel.SendMessageAsync("Command is currently disabled");
return;
}
switch (cmd.CommandType)
{
case CommandType.None:
break;
case CommandType.Private:
if (e.Guild!= null)
{
e.Channel.SendMessageAsync("You can only use this command in a private chat!");
return;
}
break;
case CommandType.Public:
if (e.Guild == null)
{
e.Channel.SendMessageAsync("You can only use this command in a server chat!");
return;
}
break;
}
if (access < cmd.AccessLevel)
{
e.Channel.SendMessageAsync("You do not have enough permissions to use this command");
return;
}
if (parameters.Count > 0)
parameters.RemoveAt(0);
if (cmd.MinParameters > 0 && parameters.Count < cmd.MinParameters)
{
e.Channel.SendMessageAsync("Not enough parameters");
return;
}
string afterCmd = e.Message.Content;
if (afterCmd.Length > cmd.Command.Length + 1)
afterCmd = afterCmd.Remove(0, cmd.Command.Length + 2);
else
afterCmd = string.Empty;
DiscordMember member = null;
if (e.Guild!= null)
{
try
{
member = e.Guild.GetMemberAsync(e.Author.Id).ConfigureAwait(false).GetAwaiter().GetResult();
}
catch (AggregateException ex)
{
if (!ex.InnerExceptions.Any(t => t is NotFoundException))
throw;
}
}
CommandEventArgs arg = new CommandEventArgs(e.Guild, e.Channel, e.Author, member,
e.Message, access, parameters, afterCmd);
ThreadPool.QueueUserWorkItem( new WaitCallback( SendCallback ), arg );
/* ThreadPool.QueueUserWorkItem(new WaitCallback(o =>
{
try
{
cmd.Invoke(this, arg);
}
catch (Exception ex)
{
if (ex is UnauthorizedException)
{
e.Channel.SendMessageAsync("Internal Error: Unauthorized (This error can happen when the bot tries to send a message to someone via DM but the user has disabled DMs from non friends)");
return;
}
if (Debug)
e.Channel.SendMessageAsync(GetDebugExceptionMessage(ex));
else
e.Channel.SendMessageAsync("Something went wrong executing this command");
}
})); */
}
catch //(Exception ex)
{
//DClient.Error(ex);
}
string GetDebugExceptionMessage(Exception ex)
{
return ("Something went wrong executing this command (L: {0} At: {1}.{2}: {3})", GetLineNumber(ex), (ex.TargetSite.DeclaringType?.FullName?? "unkown", ex.TargetSite.Name, ex.Message, ));
}
}
Lösung des Problems
Jeremy Lakemans Antwort löste es
Keine Kommentare:
Kommentar veröffentlichen