Skip to content

Instantly share code, notes, and snippets.

@monoclex
Created August 21, 2018 23:03
Show Gist options
  • Save monoclex/2dba57f4c29c51042f97421b88d26df7 to your computer and use it in GitHub Desktop.
Save monoclex/2dba57f4c29c51042f97421b88d26df7 to your computer and use it in GitHub Desktop.
Sanitize user input in discord to prevent odd formatting issues.
public static class DiscordSanitizationHelper {
private static char[] NeedsSanitation => new char[] {
'\\', '`', '-', '=', '[', ']', '\'', ',', '.', '~', '!', '@',
'#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|',
':', '"', '<', '>', '?', '/',
};
public static string DiscordSanitize(this string input) {
var output = input;
foreach (var i in NeedsSanitation)
output = output.Replace($"{i}", $"\\{i}");
return output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment