Continuous message sending in C #

I'm new to C # and I'm programming my first big project, the Discord bot. The idea is that the bot looks through comments, waiting for Cthulhu's words, and as soon as someone speaks to Cthulhu, the bot sends a message. However, in its current state, it never stops sending messages. I suspect that something is wrong with my conditional, but I have no idea how to fix it. How do I change my code to fix this?

This is my code, I have the NuGet discord.net and discord.commands packages installed:

    discord.MessageReceived += async (s, e) =>
        {
            if (e.Message.RawText.Contains("Cthulhu") )
                await e.Channel.SendMessage("*Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn*");
        };
+6
source share
1 answer

Your bot says to itself: -D

Try the following:

discord.MessageReceived += async (s, e) =>
{
    if (!e.Message.IsAuthor && e.Message.RawText.Contains("Cthulhu") )
        await e.Channel.SendMessage("*Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn*");
};
+6
source

Source: https://habr.com/ru/post/1014098/


All Articles