本文整理汇总了C#中Discord.DiscordClient.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.Disconnect方法的具体用法?C# DiscordClient.Disconnect怎么用?C# DiscordClient.Disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.DiscordClient
的用法示例。
在下文中一共展示了DiscordClient.Disconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
if (!restart)
{
rpg = new KokoroBotRPG();
loadFiles();
}
else
{
restart = false;
}
{
DiscordClientConfig config = new DiscordClientConfig();
config.VoiceMode = DiscordVoiceMode.Outgoing;
config.VoiceBufferLength = 40;
var client = new DiscordClient(config);
//Display all log messages in the console
client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");
client.MessageReceived += async (s, e) =>
{
Console.WriteLine(e.Message.User.Name + ": " + e.Message.Text);
if (!e.Message.IsAuthor)
{
var currentChannel = e.Channel;
if (e.User.Id == 95543627391959040)
{
if (e.Message.Text == "-mute")
{
mute = !mute;
await client.SendMessage(currentChannel, "KokoroBot is now mute: " + mute.ToString());
}
else if (e.Message.Text == "-clear")
{
if (voiceclient != null)
voiceclient.ClearVoicePCM();
}
else if (e.Message.Text == "-save")
{
saveFiles();
await client.SendMessage(currentChannel, "I have saved everything :3");
}
else if (e.Message.Text == "-dc")
{
quit = true;
running = false;
}
else if (e.Message.Text == "-restart")
{
await client.SendMessage(currentChannel, "Cya on the other side :3");
restart = true;
running = false;
await client.Disconnect();
}
else if (e.Message.Text.StartsWith("-join"))
{
var channels = e.Server.Channels.Where((Channel chan) => {
return e.Message.Text.Substring(5).TrimStart(' ') == chan.Name && chan.Type == ChannelType.Voice; });
if (channels.Any())
{
var channel = channels.First();
Console.WriteLine("KokoroBot tries to join Channel: " + channel.Name);
voiceclient = await client.JoinVoiceServer(channel);
voiceserver = e.Message.Server;
}
}
else if (e.Message.Text == "-leave")
{
if (voiceclient != null)
{
voiceclient.ClearVoicePCM();
await client.LeaveVoiceServer(voiceserver);
voiceclient = null;
voiceserver = null;
}
}
}
else if (e.User.Name == "part")
{
await client.SendMessage(currentChannel, "I don't like you. B-b-baka. >.<");
return;
}
if (!mute) {
if (e.Message.Text.Length > 0)
{
string[] splitmessage = e.Message.Text.Split(' ');
if (splitmessage[0] == "-kardfacts")
{
if (splitmessage.Length > 2)
{
if (splitmessage[1] == "add")
{
try
{
string finalstr = "";
for (int i = 2; i < splitmessage.Length; i++)
{
if (i != 2)
finalstr += ' ' + splitmessage[i];
//.........这里部分代码省略.........
示例2: Start
//.........这里部分代码省略.........
break;
case 5:
output = "Maybe";
break;
default: break;
}
await e.Channel.SendMessage(output);
});
Channel Log = _client.GetChannel(192699690473488384);
_client.MessageReceived += async (s, e) => {
// if (!e.Message.IsAuthor)
// {
// if (e.Message.Attachments.Length == 0)
// {
// await e.Channel.SendMessage(DateTime.Now + " UTC - " + e.User.Name + " (" + e.User.Id + "): " + e.Message.Text);
// }
// else {
// await e.Channel.SendMessage(DateTime.Now + " UTC - " + e.User.Name + " (" + e.User.Id + "): " + e.Message.Text+" | Message Contained Attachment: "+e.Message.Attachments[0].Filename+" "+e.Message.Attachments[0].Size+" "+e.Message.Attachments[0].ProxyUrl);
// }
//}
if (e.Message.IsMentioningMe()&&!e.Message.IsAuthor)
{
if(e.Message.RawText.ToLower().Contains("hi")|| e.Message.RawText.ToLower().Contains("hello"))
{
await e.Channel.SendMessage($"Hello, <@{e.User.Id}>!");
}
if (e.Message.RawText.ToLower().Contains("kys"))
{
if (e.User.Id == 142291646824841217)
{
await e.Channel.SendMessage("ok");
System.Threading.Thread.Sleep(1000);
_client.Disconnect();
System.Environment.Exit(0);
}
else
{
await e.Channel.SendMessage("no u");
}
}
}
};
_client.GetService<CommandService>().CreateCommand("addcustomcommand").Description("Adds Custom Command").Parameter("Name").Parameter("Contents",ParameterType.Unparsed).Do(async e =>
{
if (e.Message.RawText.Contains("@everyone")|| e.Message.RawText.Contains("@here"))
{
await e.Channel.SendMessage("Don't ping everyone you faggot");
return;
}
if (e.Message.Attachments.Length > 0)
{
await e.Channel.SendMessage("I don't support files you retard.");
return;
}
XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>));
FileStream file1 = new FileStream("commands.xml", FileMode.OpenOrCreate);
List<CustomCommand> list1 = (List<CustomCommand>)xml1.Deserialize(file1);
file1.Close();
if (list1.Contains(new CustomCommand(e.GetArg("Name").ToLower(), e.GetArg("Contents"))) || forbodens.Contains<string>(e.GetArg("Name")))
{
await e.Channel.SendMessage("That already exists.");
return;
}
if (commandBuilders.ContainsKey(e.GetArg("Name").ToLower()))