Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous Message Sending in C#

Tags:

c#

discord.net

I'm new to C#, and I am programming my first big project, a Discord bot. The idea is that the bot scans through comments, waiting for the word Cthulhu, and once someone says Cthulhu, the bot sends a message. However, in it's current state, it never stops sending messages. I suspect there's something wrong with my conditional, but have no idea how to fix it. How should I modify my code to fix this?

This is my code, I have the NuGet packages discord.net and discord.commands 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*");
        };
like image 360
Amature Programmer Avatar asked Jan 15 '17 00:01

Amature Programmer


1 Answers

Your bot is talking to itself :-D

Try this:

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*");
};
like image 96
Stuart Avatar answered Sep 23 '22 23:09

Stuart