本文整理汇总了C#中Discord.DiscordClient.CreatePrivateChannel方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.CreatePrivateChannel方法的具体用法?C# DiscordClient.CreatePrivateChannel怎么用?C# DiscordClient.CreatePrivateChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.DiscordClient
的用法示例。
在下文中一共展示了DiscordClient.CreatePrivateChannel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main() {
//load credentials from credentials.json
bool loadTrello = false;
try {
creds = JsonConvert.DeserializeObject<Credentials>(File.ReadAllText("credentials.json"));
botMention = creds.BotMention;
if (string.IsNullOrWhiteSpace(creds.GoogleAPIKey)) {
Console.WriteLine("No google api key found. You will not be able to use music and links won't be shortened.");
} else {
Console.WriteLine("Google API key provided.");
GoogleAPIKey = creds.GoogleAPIKey;
}
if (string.IsNullOrWhiteSpace(creds.TrelloAppKey)) {
Console.WriteLine("No trello appkey found. You will not be able to use trello commands.");
} else {
Console.WriteLine("Trello app key provided.");
TrelloAppKey = creds.TrelloAppKey;
loadTrello = true;
}
if (creds.ForwardMessages != true)
Console.WriteLine("Not forwarding messages.");
else {
ForwardMessages = true;
Console.WriteLine("Forwarding messages.");
}
if(string.IsNullOrWhiteSpace(creds.SoundCloudClientID))
Console.WriteLine("No soundcloud Client ID found. Soundcloud streaming is disabled.");
else
Console.WriteLine("SoundCloud streaming enabled.");
OwnerID = creds.OwnerID;
password = creds.Password;
} catch (Exception ex) {
Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}");
Console.ReadKey();
return;
}
//create new discord client
client = new DiscordClient(new DiscordConfigBuilder() {
MessageCacheSize = 0,
ConnectionTimeout = 60000,
});
//create a command service
var commandService = new CommandService(new CommandServiceConfigBuilder {
AllowMentionPrefix = false,
CustomPrefixHandler = m => 0,
HelpMode = HelpMode.Disabled
});
//reply to personal messages and forward if enabled.
client.MessageReceived += Client_MessageReceived;
//add command service
var commands = client.Services.Add<CommandService>(commandService);
//create module service
var modules = client.Services.Add<ModuleService>(new ModuleService());
//add audio service
var audio = client.Services.Add<AudioService>(new AudioService(new AudioServiceConfigBuilder() {
Channels = 2,
EnableEncryption = false,
EnableMultiserver = true,
Bitrate = 128,
}));
//install modules
modules.Add(new Administration(), "Administration", ModuleFilter.None);
modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None);
modules.Add(new Conversations(), "Conversations", ModuleFilter.None);
modules.Add(new Gambling(), "Gambling", ModuleFilter.None);
modules.Add(new Games(), "Games", ModuleFilter.None);
modules.Add(new Music(), "Music", ModuleFilter.None);
modules.Add(new Searches(), "Searches", ModuleFilter.None);
if (loadTrello)
modules.Add(new Trello(), "Trello", ModuleFilter.None);
modules.Add(new NSFW(), "NSFW", ModuleFilter.None);
//run the bot
client.ExecuteAndWait(async () => {
await client.Connect(creds.Username, creds.Password);
Console.WriteLine("-----------------");
Console.WriteLine(NadekoStats.Instance.GetStats());
Console.WriteLine("-----------------");
try {
OwnerPrivateChannel = await client.CreatePrivateChannel(OwnerID);
} catch {
Console.WriteLine("Failed creating private channel with the owner");
}
Classes.Permissions.PermissionsHandler.Initialize();
client.ClientAPI.SendingRequest += (s, e) =>
{
var request = e.Request as Discord.API.Client.Rest.SendMessageRequest;
if (request != null) {
if (string.IsNullOrWhiteSpace(request.Content))
//.........这里部分代码省略.........
示例2: Main
//.........这里部分代码省略.........
Channels = 2,
EnableEncryption = false,
Bitrate = 128,
}));
//install modules
modules.Add(new HelpModule(), "Help", ModuleFilter.None);
modules.Add(new AdministrationModule(), "Administration", ModuleFilter.None);
modules.Add(new UtilityModule(), "Utility", ModuleFilter.None);
modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None);
modules.Add(new Conversations(), "Conversations", ModuleFilter.None);
modules.Add(new GamblingModule(), "Gambling", ModuleFilter.None);
modules.Add(new GamesModule(), "Games", ModuleFilter.None);
#if !NADEKO_RELEASE
modules.Add(new MusicModule(), "Music", ModuleFilter.None);
#endif
modules.Add(new SearchesModule(), "Searches", ModuleFilter.None);
modules.Add(new NSFWModule(), "NSFW", ModuleFilter.None);
modules.Add(new ClashOfClansModule(), "ClashOfClans", ModuleFilter.None);
modules.Add(new PokemonModule(), "Pokegame", ModuleFilter.None);
modules.Add(new TranslatorModule(), "Translator", ModuleFilter.None);
modules.Add(new CustomReactionsModule(), "Customreactions", ModuleFilter.None);
if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey))
modules.Add(new TrelloModule(), "Trello", ModuleFilter.None);
//run the bot
Client.ExecuteAndWait(async () =>
{
await Task.Run(() =>
{
Console.WriteLine("Specific config started initializing.");
var x = SpecificConfigurations.Default;
Console.WriteLine("Specific config done initializing.");
});
await PermissionsHandler.Initialize();
try
{
await Client.Connect(Creds.Token, TokenType.Bot).ConfigureAwait(false);
}
catch (Exception ex)
{
Console.WriteLine($"Token is wrong. Don't set a token if you don't have an official BOT account.");
Console.WriteLine(ex);
Console.ReadKey();
return;
}
#if NADEKO_RELEASE
await Task.Delay(300000).ConfigureAwait(false);
#else
await Task.Delay(1000).ConfigureAwait(false);
#endif
Console.WriteLine("-----------------");
Console.WriteLine(await NadekoStats.Instance.GetStats().ConfigureAwait(false));
Console.WriteLine("-----------------");
OwnerPrivateChannels = new List<Channel>(Creds.OwnerIds.Length);
foreach (var id in Creds.OwnerIds)
{
try
{
OwnerPrivateChannels.Add(await Client.CreatePrivateChannel(id).ConfigureAwait(false));
}
catch
{
Console.WriteLine($"Failed creating private channel with the owner {id} listed in credentials.json");
}
}
Client.ClientAPI.SendingRequest += (s, e) =>
{
var request = e.Request as Discord.API.Client.Rest.SendMessageRequest;
if (request == null) return;
// meew0 is magic
request.Content = request.Content?.Replace("@everyone", "@everyοne").Replace("@here", "@һere") ?? "_error_";
if (string.IsNullOrWhiteSpace(request.Content))
e.Cancel = true;
};
#if NADEKO_RELEASE
Client.ClientAPI.SentRequest += (s, e) =>
{
Console.WriteLine($"[Request of type {e.Request.GetType()} sent in {e.Milliseconds}]");
var request = e.Request as Discord.API.Client.Rest.SendMessageRequest;
if (request == null) return;
Console.WriteLine($"[Content: { request.Content }");
};
#endif
NadekoBot.Ready = true;
NadekoBot.OnReady();
Console.WriteLine("Ready!");
//reply to personal messages and forward if enabled.
Client.MessageReceived += Client_MessageReceived;
});
Console.WriteLine("Exiting...");
Console.ReadKey();
}