【问题标题】:C# Discord Bot: How can I check if a user has said a specific phrase?C# Discord Bot:如何检查用户是否说过特定短语?
【发布时间】:2017-11-05 12:11:19
【问题描述】:

所以我正在尝试创建一个机器人来响应我的不和谐服务器中的某一行文本。我想检查我的朋友是否说“不”(他说了很多,他有一个五岁的心态),我希望我的机器人回应这个声明。我对 C# 还比较陌生,并且到处都在拼命寻找这个答案。如果您能提供帮助,将不胜感激!

【问题讨论】:

  • 你能告诉我们你到目前为止尝试过的代码吗?以这种方式为您提供帮助会容易得多。
  • 正如@ThomasFonn 所说,到目前为止你得到了什么?您是否研究过如何在 C# 中创建不和谐机器人,或者这是您的实际问题?

标签: c# command bots discord.net


【解决方案1】:

这应该可以完成工作:

using System;
using Discord;

class Program
{
    static public DiscordClient client;

    static void Main(string[] args)
    {
        client = new DiscordClient(input =>
        {
            input.LogLevel = LogSeverity.Info;
        });
        client.MessageReceived += Client_MessageReceived;
        client.ExecuteAndWait(async () =>
        {
            await client.Connect("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", TokenType.Bot);
        });
    }

    static async private void Client_MessageReceived(object sender, MessageEventArgs e)
    {
        if (e.Message.Text == "no u")
            await e.Channel.SendMessage("You have the mentality of a five year old");
    }
}

【讨论】:

    【解决方案2】:

    您应该从 Discord.Net GitHub 上查看 this 示例。本质上,您需要订阅MessageReceived 事件,然后根据消息进行回复。

    【讨论】:

      猜你喜欢
      • 2018-12-16
      • 2021-09-19
      • 2021-05-03
      • 2021-03-08
      • 2019-11-01
      • 2022-08-19
      • 2019-02-26
      • 1970-01-01
      • 2019-06-01
      相关资源
      最近更新 更多