当某个用户向频道发送消息时如何运行方法

时间:2019-02-07 19:10:52

标签: c# bots discord

我正在尝试创建一个当特定用户向频道发送消息时会对其进行回复的漫游器。我拥有适用于bot的所有代码,如果我使用命令来运行代码,则可以使我的代码正常工作-例如,如果我编写

[Command("reply")]

在我的代码上方。

但是我希望我的代码仅在此人向聊天室发送消息时才运行。

我没有做太多尝试,因为我不知道下一步该怎么做。一切工作正常,我只是不知道执行此操作的正确方法。

下面是将包含我所有命令的类。 messageRecieved方法是将消息发送到聊天室时要运行的代码。

public class Misc : ModuleBase<SocketCommandContext>
{
    ulong id = 169526919472218112;

    string[] jarjarQuotes = { "Mesa called Jar Jar Binks, mesa your humble servant!",
    "Hmm... yousa point is well seen. Dis way, hurry!",
    "Yousa should follow me now, okeeday? My warning yous: Gungans no like outsiders. Don't 'spect a warm welcome.",
    "How wuude!",
    "You'd say, boom de gasa... den crashded da boss's heyblibber... den banished.",
    "Uh-oh! Biiiiiig Goober fish!",
    "Monsters out dere, leakin in here, all sinkin an no power? When are yousa tinkin' wesa in trouble?!",
    "Oh, maxi big da Force...",
    "Getin very scared and grabin dat Jedi, den pah... mesa here.",
    "Dissen gonna be bery messy! Me no watchin!",
    "Icky, icky goo!"};
    [Command("Ben")]
    public async Task GetQuote()
    {
        ulong currentID = Context.User.Id;
        if (id == currentID)
        {
            Random rnd = new Random();
            int rollValue = rnd.Next(0, 10);
            Random msgNum = new Random();
            int msgValue = rnd.Next(0, 10);

            if (5 == 5)
            {
                Context.Channel.SendMessageAsync(jarjarQuotes[msgValue]);
            }
        }
    }

感谢您的帮助

0 个答案:

没有答案