Reputation: 88
I'm trying to make a plugin in Discord.NET 1.0 which censor certain words, and was looking online for an event that would trigger when someone sent a text message, but couldn't fine one anywhere. I know how to do this in 0.9.6, but is there a way in 1.0?
Any help would be much appreciated!
Upvotes: 1
Views: 1121
Reputation:
So first you would make an array of the words you want to censor:
String[] badWords = {"word1","word2", "word3"};
Then you would want to check if the message sent by the user contains these messages, and then store that to a dictionary.
for (int i = 0; i < badWords.Length; i++)
{
if (msg.Content.Contains(badWords[i]))
{
Console.WriteLine("true");
if (wordOffences.ContainsKey(msg.Author.ToString()))
{
wordOffences[msg.Author.ToString()] += 1;
Console.WriteLine("if");
Console.WriteLine(wordOffences[msg.Author.ToString()]);
File.WriteAllText(@"c:\Users\me\Desktop\real.json", JsonConvert.SerializeObject(wordOffences));
if (wordOffences[msg.Author.ToString()] >= 3)
{
Console.WriteLine("really true");
await m.Channel.SendMessageAsync("@Staff have been notified. Hey buddy watch your language! This is offence: " + wordOffences[msg.Author.ToString()]);
}
else
{
Console.WriteLine("y");
await m.Channel.SendMessageAsync("Hey buddy watch your language! This is offence: " + wordOffences[msg.Author.ToString()]);
}
}
else
{
Console.WriteLine("runmf");
wordOffences.Add(msg.Author.ToString(), 1);
Console.WriteLine(wordOffences[msg.Author.ToString()]);
await m.Channel.SendMessageAsync("Hey buddy watch your language! This is offence: " + wordOffences[msg.Author.ToString()]);
File.WriteAllText(@"c:\Users\me\Desktop\real.json", JsonConvert.SerializeObject(wordOffences));
}
i = badWords.Length;
}
Using this you can store the number of offences the user has to a json file so it is permanent. You should put this in your:
public async Task HandleCommandAsync(SocketMessage m)
Upvotes: 0