本文整理汇总了C#中Discord.DiscordClient.GetUser方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.GetUser方法的具体用法?C# DiscordClient.GetUser怎么用?C# DiscordClient.GetUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.DiscordClient
的用法示例。
在下文中一共展示了DiscordClient.GetUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCommand
void IService.Install(DiscordClient client)
{
_client = client;
_config.Lock();
if (_config.HelpMode != HelpMode.Disable)
{
CreateCommand("help")
.Parameter("command", ParameterType.Multiple)
.Hide()
.Description("Returns information about commands.")
.Do((Func<CommandEventArgs, Task>)(async e =>
{
Channel replyChannel = _config.HelpMode == HelpMode.Public ? e.Channel : await client.CreatePMChannel(e.User);
if (e.Args.Length > 0) //Show command help
{
var map = _map.GetItem(string.Join(" ", e.Args));
if (map != null)
await ShowCommandHelp(map, e.User, e.Channel, replyChannel);
else
await client.SendMessage(replyChannel, "Unable to display help: Unknown command.");
}
else //Show general help
await ShowGeneralHelp(e.User, e.Channel, replyChannel);
}));
}
client.MessageReceived += async (s, e) =>
{
if (_allCommands.Count == 0) return;
if (e.Message.IsAuthor) return;
string msg = e.Message.Text;
if (msg.Length == 0) return;
// Check ignored before doing work
if (_getIgnoredChannelFlag != null ? _getIgnoredChannelFlag(e.Message.Channel, e.User) : false)
return;
//Check for command char if one is provided
var chars = _config.CommandChars;
if (chars.Length > 0)
{
bool hasCommandChar = chars.Contains(msg[0]);
if (!hasCommandChar && (e.Message.Channel.IsPrivate ? _config.RequireCommandCharInPrivate : _config.RequireCommandCharInPublic))
{
if (_config.MentionCommandChar >= 1 && e.Message.IsMentioningMe)
{
// It's lame we have to do this, but our User isn't exposed by Discord.Net, so we don't know our name
User nekouser = client.GetUser(e.Server, client.CurrentUserId);
string neko = '@'+nekouser.Name;
if (neko.Length+2 > msg.Length || (e.Message.MentionedRoles.Contains(e.Server.EveryoneRole) && e.Message.MentionedUsers.Where(u => u == nekouser).Count() == 0))
{
NonCommands(e);
return;
}
if (msg.StartsWith(neko))
msg = msg.Substring(neko.Length+1);
else
{
int index = _config.MentionCommandChar > 1 ? msg.LastIndexOf(neko) : -1;
if (index == -1)
{
NonCommands(e);
return;
}
msg = msg.Substring(0, index-1);
}
// Ideally, don't let the command know that we were mentioned, if this is the only mention
/*if (msg.IndexOf(neko) != -1)
{
e.Message.MentionedUsers = e.Message.MentionedUsers.Where(u => u == nekouser);
e.Message.IsMentioningMe = false;
}*/
}
else
{
NonCommands(e);
return;
}
}
else if (hasCommandChar)
msg = msg.Substring(1);
}
//Parse command
IEnumerable<Command> commands;
int argPos;
CommandParser.ParseCommand(msg, _map, out commands, out argPos);
if (commands == null)
{
CommandEventArgs errorArgs = new CommandEventArgs(e.Message, null, null);
RaiseCommandError(CommandErrorType.UnknownCommand, errorArgs);
NonCommands(e);
return;
}
else
{
foreach (var command in commands)
//.........这里部分代码省略.........