因此,我正在尝试创建一个对我的Discord Server中某种文本响应的机器人。我想检查我的朋友是否说"不"(他说很多,他有一个五岁的人的心态(,我希望我的机器人回应这一说法。我对C#仍然相对较新,并且无所不能地寻找这个答案。如果您可以提供帮助,那将是非常感谢的!
您应该从discord.net github结帐此示例。本质上,您需要订阅MessageReceived
事件,然后根据消息回复。
这应该完成工作:
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");
}
}