Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
discord bot c#读取收到的直接消息_C#_Bots_Discord_Discord.net - Fatal编程技术网

discord bot c#读取收到的直接消息

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

我目前正在尝试为我的Discord服务器创建自己的bot。我希望用户能够键入命令**事件,然后bot将直接向该用户发送消息,并就事件向其询问一些问题,如标题、时间等

我可以让机器人直接向用户发送消息,但我找不到如何让机器人读取用户发送回的消息

以下是我目前的代码:

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
}