discord bot c#读取收到的直接消息
我目前正在尝试为我的Discord服务器创建自己的bot。我希望用户能够键入命令**事件,然后bot将直接向该用户发送消息,并就事件向其询问一些问题,如标题、时间等 我可以让机器人直接向用户发送消息,但我找不到如何让机器人读取用户发送回的消息 以下是我目前的代码:discord bot c#读取收到的直接消息,c#,bots,discord,discord.net,C#,Bots,Discord,Discord.net,我目前正在尝试为我的Discord服务器创建自己的bot。我希望用户能够键入命令**事件,然后bot将直接向该用户发送消息,并就事件向其询问一些问题,如标题、时间等 我可以让机器人直接向用户发送消息,但我找不到如何让机器人读取用户发送回的消息 以下是我目前的代码: public class Event : ModuleBase<SocketCommandContext> { private static IUser currentUser; private Disc
public class Event : ModuleBase<SocketCommandContext> {
private static IUser currentUser;
private DiscordSocketClient _client;
[Command("event")]
public async Task EventAsync() {
_client = new DiscordSocketClient();
var id = Context.User.Mention;
if(currentUser == null) {
foreach(var user in Context.Guild.Users) {
if(("<@!" + user.Id.ToString() + ">") == id) {
currentUser = user;
id = user.Mention;
break;
}
}
}
await currentUser.SendMessageAsync("Enter event title:");
}
}
公共类事件:ModuleBase{
私有静态用户;
私人DiscordSocketClient _客户端;
[命令(“事件”)]
公共异步任务EventAsync(){
_client=新的DiscordSocketClient();
var id=Context.User.notice;
if(currentUser==null){
foreach(Context.Guild.Users中的var用户){
如果((“”)=id){
当前用户=用户;
id=用户。提及;
打破
}
}
}
等待currentUser.SendMessageAsync(“输入事件标题:”);
}
}
我能弄明白这一点。在main program.cs中
static void Main(string[] args)
=> new Program().RunBotAsync().GetAwaiter().GetResult();
public async Task RunBotAsync() {
_client.MessageReceived += MessageReceived;
}
private async Task MessageReceived(SocketMessage msg) {
//Code to direct message here
}