问题描述
我正在制作我的第一个机器人,除了这个命令之外,每个命令都有效。我试图让机器人将 dm 发送给两个指定的用户(第一个是使用命令的用户,第二个是由第一个用户指定的),然后读取这些用户输入的内容,但它不起作用。此外,我认为问题可能出在事件中,但我真的不知道。
public class rockpaperscisors : ModuleBase<SocketCommandContext>
{
private SocketUser User1 = null;
private SocketUser User2 = null;
private string User1input = "";
private string User2input = "";
taskcompletionsource<bool> tcs = null;
taskcompletionsource<bool> tcs2 = null;
[Command("rps",RunMode = RunMode.Async)]
[Summary("Rock paper scissors")]
public async Task Rps([Remainder] SocketGuildUser user)
{
var commandused = Context.Channel;
var discordclien = new discordSocketClient();
discordclien.MessageReceived += message;
User2 = user;
User1 = Context.User;
await User1.SendMessageAsync("Type rock,paper,or scissors");
await User2.SendMessageAsync("Type rock,or scissors");
tcs = new taskcompletionsource<bool>();
tcs2 = new taskcompletionsource<bool>();
await tcs.Task;
await tcs2.Task;
await commandused.SendMessageAsync($"{User2input} {User1input}");
}
private Task message(SocketMessage arg)
{
if (arg.Author == User1)
{
string a = arg.ToString();
switch (a)
{
case "rock":
this.User1input = "rock";
tcs?.TrySetResult(true);
break;
case "paper":
this.User1input = "paper";
tcs?.TrySetResult(true);
break;
case "scissors":
this.User1input = "scissors";
tcs?.TrySetResult(true);
break;
}
return Task.CompletedTask;
}
if (arg.Author == User2)
{
string a = arg.ToString();
switch (a)
{
case "rock":
this.User2input = "rock";
tcs2?.TrySetResult(true);
break;
case "paper":
this.User2input = "paper";
tcs2?.TrySetResult(true);
break;
case "scissors":
this.User2input = "scissors";
tcs2?.TrySetResult(true);
break;
}
return Task.CompletedTask;
}
return Task.CompletedTask;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)