本文整理汇总了C#中Discord.DiscordClient.GetChannel方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.GetChannel方法的具体用法?C# DiscordClient.GetChannel怎么用?C# DiscordClient.GetChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.DiscordClient
的用法示例。
在下文中一共展示了DiscordClient.GetChannel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FinishLoading
public bool FinishLoading(DiscordClient client)
{
Channel channel = client.GetChannel(ChannelId);
if (channel == null)
return false;
Channel = channel;
return true;
}
示例2: StringBuilder
void IModule.Install(ModuleManager manager)
{
_manager = manager;
_client = manager.Client;
_http = _client.Services.Get<HttpService>();
_settings = _client.Services.Get<SettingsService>()
.AddModule<TwitchModule, Settings>(manager);
manager.CreateCommands("streams", group =>
{
group.MinPermissions((int)PermissionLevel.BotOwner);
group.CreateCommand("list")
.Do(async e =>
{
StringBuilder builder = new StringBuilder();
var settings = _settings.Load(e.Server);
foreach (var channel in settings.Channels)
builder.AppendLine($"{_client.GetChannel(channel.Key)}:\n {string.Join(", ", channel.Value.Streams.Select(x => x.Key))}");
await _client.Reply(e, "Linked Streams", builder.ToString());
});
group.CreateCommand("add")
.Parameter("twitchuser")
.Parameter("channel", ParameterType.Optional)
.Do(async e =>
{
var settings = _settings.Load(e.Server);
Channel channel;
if (e.Args[1] != "")
channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
else
channel = e.Channel;
if (channel == null) return;
var channelSettings = settings.GetOrAddChannel(channel.Id);
if (channelSettings.AddStream(e.Args[0]))
{
await _settings.Save(e.Server, settings);
await _client.Reply(e, $"Linked stream {e.Args[0]} to {channel.Name}.");
}
else
await _client.Reply(e, $"Stream {e.Args[0]} is already linked to {channel.Name}.");
});
group.CreateCommand("remove")
.Parameter("twitchuser")
.Parameter("channel", ParameterType.Optional)
.Do(async e =>
{
var settings = _settings.Load(e.Server);
Channel channel;
if (e.Args[1] != "")
channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
else
channel = e.Channel;
if (channel == null) return;
var channelSettings = settings.GetOrAddChannel(channel.Id);
if (channelSettings.RemoveStream(e.Args[0]))
{
await _settings.Save(e.Server.Id, settings);
await _client.Reply(e, $"Unlinked stream {e.Args[0]} from {channel.Name}.");
}
else
await _client.Reply(e, $"Stream {e.Args[0]} is not currently linked to {channel.Name}.");
});
group.CreateGroup("set", set =>
{
set.CreateCommand("sticky")
.Parameter("value")
.Parameter("channel", ParameterType.Optional)
.Do(async e =>
{
bool value = false;
bool.TryParse(e.Args[0], out value);
Channel channel;
if (e.Args[1] != "")
channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
else
channel = e.Channel;
if (channel == null) return;
var settings = _settings.Load(e.Server);
var channelSettings = settings.GetOrAddChannel(channel.Id);
if (channelSettings.UseSticky && !value && channelSettings.StickyMessageId != null)
{
var msg = channel.GetMessage(channelSettings.StickyMessageId.Value);
try { await msg.Delete(); }
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}
channelSettings.UseSticky = value;
await _settings.Save(e.Server, settings);
await _client.Reply(e, $"Stream sticky for {channel.Name} set to {value}.");
});
});
});
//.........这里部分代码省略.........
示例3: StringBuilder
void IModule.Install(ModuleManager manager)
{
_manager = manager;
_client = manager.Client;
_http = _client.Services.Get<HttpService>();
_settings = _client.Services.Get<SettingsService>()
.AddModule<GithubModule, Settings>(manager);
manager.CreateCommands("repos", group =>
{
group.MinPermissions((int)PermissionLevel.BotOwner);
group.CreateCommand("list")
.Do(async e =>
{
StringBuilder builder = new StringBuilder();
var settings = _settings.Load(e.Server);
foreach (var repo in settings.Repos.OrderBy(x => x.Key))
builder.AppendLine($"{repo.Key} [{string.Join(",", repo.Value.Branches)}] => {_client.GetChannel(repo.Value.ChannelId)?.Name ?? "Unknown"}");
await _client.Reply(e, "Linked Repos", builder.ToString());
});
group.CreateCommand("add")
.Parameter("githubrepo")
.Parameter("channel", ParameterType.Optional)
.Do(async e =>
{
var settings = _settings.Load(e.Server);
Channel channel;
if (e.Args[1] != "")
channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
else
channel = e.Channel;
if (channel == null) return;
string url = FilterUrl(e.Args[0]);
if (settings.AddRepo(url, channel.Id))
{
await _settings.Save(e.Server.Id, settings);
await _client.Reply(e, $"Linked repo {url} to {channel.Name}.");
}
else
await _client.Reply(e, $"Error: Repo {url} is already being watched.");
});
group.CreateCommand("remove")
.Parameter("githubrepo")
.Do(async e =>
{
var settings = _settings.Load(e.Server);
string url = FilterUrl(e.Args[0]);
if (settings.RemoveRepo(url))
{
await _settings.Save(e.Server.Id, settings);
await _client.Reply(e, $"Unlinked repo {url}.");
}
else
await _client.Reply(e, $"Error: Repo {url} is not currently being watched.");
});
group.CreateCommand("addbranch")
.Parameter("githubrepo")
.Parameter("branch")
.Do(async e =>
{
var settings = _settings.Load(e.Server);
string url = FilterUrl(e.Args[0]);
var repo = settings.Repos[url];
if (repo != null)
{
if (repo.AddBranch(e.Args[1]))
{
await _settings.Save(e.Server.Id, settings);
await _client.Reply(e, $"Added branch {url}/{e.Args[1]}.");
}
else
await _client.Reply(e, $"Error: Branch {url}/{e.Args[1]} is already being watched.");
}
else
await _client.Reply(e, $"Error: Repo {url} is not currently being watched.");
});
group.CreateCommand("removebranch")
.Parameter("githubrepo")
.Parameter("branch")
.Do(async e =>
{
var settings = _settings.Load(e.Server);
string url = FilterUrl(e.Args[0]);
var repo = settings.Repos[url];
if (repo != null)
{
if (repo.RemoveBranch(e.Args[1]))
{
await _settings.Save(e.Server.Id, settings);
await _client.Reply(e, $"Removed branch {url}/{e.Args[1]}.");
}
else
await _client.Reply(e, $"Error: Branch {url}/{e.Args[1]} is not being watched.");
}
//.........这里部分代码省略.........
示例4:
void IModule.Install(ModuleManager manager)
{
_manager = manager;
_client = manager.Client;
_http = _client.Services.Get<HttpService>();
_settings = _client.Services.Get<SettingsService>()
.AddModule<FeedModule, Settings>(manager);
manager.CreateCommands("feeds", group =>
{
group.MinPermissions((int)PermissionLevel.BotOwner);
group.CreateCommand("list")
.Do(async e =>
{
var settings = _settings.Load(e.Server);
var response = settings.Feeds
.OrderBy(x => x.Key)
.Select(x => $"{x.Key} => {_client.GetChannel(x.Value.ChannelId)?.Name ?? "Unknown"}");
await _client.Reply(e, "Linked Feeds", response);
});
group.CreateCommand("add")
.Parameter("url")
.Parameter("channel", ParameterType.Optional)
.Do(async e =>
{
var settings = _settings.Load(e.Server);
Channel channel;
if (e.Args[1] != "")
channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
else
channel = e.Channel;
if (channel == null) return;
if (settings.AddFeed(e.Args[0], channel.Id))
{
await _settings.Save(e.Server, settings);
await _client.Reply(e, $"Linked feed {e.Args[0]} to {channel.Name}");
}
else
await _client.Reply(e, $"Feed {e.Args[0]} is already linked to a channel.");
});
group.CreateCommand("remove")
.Parameter("url")
.Do(async e =>
{
var settings = _settings.Load(e.Server);
if (settings.RemoveFeed(e.Args[0]))
{
await _settings.Save(e.Server, settings);
await _client.Reply(e, $"Unlinked feed {e.Args[0]}.");
}
else
await _client.Reply(e, $"Feed {e.Args[0]} is not currently linked to a channel.");
});
});
_client.Connected += (s, e) =>
{
if (!_isRunning)
{
Task.Run(Run);
_isRunning = true;
}
};
}
示例5: Start
//.........这里部分代码省略.........
//};
// _client.UserLeft += async (s, e) =>
// {
//await e.Server.DefaultChannel.SendMessage(e.User.Name + " left FeelsBadMan");
// };
_client.GetService<CommandService>().CreateCommand("8ball").Description("Simple 8ball command").Parameter("memes", ParameterType.Unparsed).Do(async e => {
Random rand = new Random();
string output = "";
switch (rand.Next(6))
{
case 0:
output = "I don't know faggot";
break;
case 1:
output = "Yes";
break;
case 2:
output = "No";
break;
case 3:
output = "Kys";
break;
case 4:
output = "Ask me later";
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");
}
示例6: HandleMessage
//.........这里部分代码省略.........
await e.Channel.SendMessage("Format is !playsong (songname)");
}
}
else if (recievedMessage.ToLower().Contains("!addsong"))
{
var commandList = recievedMessage.Split(' ').ToList();
if (commandList.Count > 1)
{
var youtubeUrl = commandList.Skip(1).Aggregate((i, j) => i + " " + j);
var channelName = "Koromo's Room";
var koromos_room = "twitch_chat";
// Change for servers
var voiceClient = await VoiceChannel.JoinAudio();
if (!IsPlayingMusic)
{
IsPlayingMusic = true;
Playlist.Add(youtubeUrl);
await MusicService.ExecutePlaylist(voiceClient, Playlist, MusicChatChannel);
IsPlayingMusic = false;
}
else
{
Playlist.Add(youtubeUrl);
await e.Channel.SendMessage("added to playlist");
}
}
else
{
await e.Channel.SendMessage("Format is !downloadsong (Youtube URL)");
}
}
else if (recievedMessage.ToLower().Equals("!skip"))
{
IsSkipSong = true;
await e.Channel.SendMessage("Song skipped");
}
else if (recievedMessage.ToLower().Contains("!matchvideo"))
{
var commandList = recievedMessage.ToLower().Split(' ').ToList();
if (commandList.Count > 1)
{
string char1 = commandList[1];
string char2 = "";
if (commandList.Count > 2)
char2 = commandList[2];
var link = WebServices.GetMatchVideo(char1, char2);
await e.Channel.SendMessage(link);
}
else
{
await e.Channel.SendMessage("Format is !matchvideo (char1) (char2)");
}
}
else if (recievedMessage.ToLower().StartsWith("!unbansonify"))
{
var commandList = recievedMessage.ToLower().Split(' ').ToList();
if (commandList.Count > 1)
{
var inputLine = commandList.Skip(1).Aggregate((i, j) => i + " " + j);
var correctedSentence = MilliaUtils.GetAutoCorrectedSentence(inputLine);
await e.Channel.SendMessage(correctedSentence);
}
}
else if (recievedMessage.ToLower().StartsWith("!add"))
{
var commandList = recievedMessage.Split(' ').ToList();
if (commandList.Count > 1)
{
var command = commandList[0].Replace("!add", "");
var adaptor = new CommandsTableAdapter();
var link = commandList.Skip(1).Aggregate((i, j) => i + " " + j);
adaptor.Insert(command, link);
}
else
{
await e.Channel.SendMessage("Format is !add (URL)");
}
}
// Must be last
else if (recievedMessage.StartsWith("!"))
{
var commandList = recievedMessage.Split(' ').ToList();
var value = MilliaUtils.GetCommandLink(commandList[0].Replace("!", ""));
if (!String.IsNullOrEmpty(value))
await e.Channel.SendMessage(value);
}
}
client.GetChannel(1);
};
}