jeudi 10 mai 2018

Discord.NET C# Change Content of SocketMessage

So I am listening to the event whenever anyone on the server sends a message to any text channel with my bot. I want to detect swear words like "fuck" and change it to "f*ck". I was unable to replace my message just normally only with reflection but it did not help since it only replaced it in the instance of the SocketMessage but it did not change the message on the server.

Any solution for that?

Framework: 4.6 Discord.NET: 1.0.2

Code:

private async Task MsgRec(SocketMessage e)
{
    try
    {
        if (e.Content.Contains("fuck"))
        {
            foreach(PropertyInfo info in typeof(SocketMessage).GetProperties())
            {
                if (info.Name == "Content")
                {
                    info.SetValue(e,e.Content.Replace("fuck", "f*ck"));
                }
            }
        }
    }
    catch (Exception ex)
    {
        await e.Author.SendMessageAsync(ex.StackTrace);
    }
}





Aucun commentaire:

Enregistrer un commentaire