非静态字段、方法或 属性 Bot_MessageReceived 需要对象引用 我该如何解决此错误?
An object reference is required for non-static field, method or property Bot_MessageReceived how do I fix this error?
所以我正在尝试为 Discord 创建一个机器人,这是一个为游戏玩家构建的在线语音和聊天程序,但在调试时出现此错误。
Error CS0501 'Program.Bot_MessageReceived(object, MessageEventArgs)'
must declare a body because it is not marked abstract, extern, or
partial ConsoleApplication1 c:\users\nate\documents\visual studio
2015\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs
这是我的代码
using Discord;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBotTest1
{
class Program
{
static void Main(string[] args)
{
var bot = new DiscordClient();
bot.MessageReceived += Bot_MessageReceived;
bot.Connect("natebot@natesbot.tk", "password");
bot.Wait();
}
// This code is run everytime a message is received
private void Bot_MessageReceived(object sender, MessageEventArgs e)
{
Console.WriteLine("{0} said: {1}", e.User.Name, e.Message.Text);
}
}
}
创建函数static
private static void Bot_MessageReceived(object sender, MessageEventArgs e)
{
Console.WriteLine("{0} said: {1}", e.User.Name, e.Message.Text);
}
所以我正在尝试为 Discord 创建一个机器人,这是一个为游戏玩家构建的在线语音和聊天程序,但在调试时出现此错误。
Error CS0501 'Program.Bot_MessageReceived(object, MessageEventArgs)' must declare a body because it is not marked abstract, extern, or partial ConsoleApplication1 c:\users\nate\documents\visual studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs
这是我的代码
using Discord;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBotTest1
{
class Program
{
static void Main(string[] args)
{
var bot = new DiscordClient();
bot.MessageReceived += Bot_MessageReceived;
bot.Connect("natebot@natesbot.tk", "password");
bot.Wait();
}
// This code is run everytime a message is received
private void Bot_MessageReceived(object sender, MessageEventArgs e)
{
Console.WriteLine("{0} said: {1}", e.User.Name, e.Message.Text);
}
}
}
创建函数static
private static void Bot_MessageReceived(object sender, MessageEventArgs e)
{
Console.WriteLine("{0} said: {1}", e.User.Name, e.Message.Text);
}