本文整理汇总了C#中Discord.DiscordClient.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.SendMessage方法的具体用法?C# DiscordClient.SendMessage怎么用?C# DiscordClient.SendMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.DiscordClient
的用法示例。
在下文中一共展示了DiscordClient.SendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Install
public void Install(ModuleManager manager)
{
_client = manager.Client;
manager.CreateCommands("", group =>
{
group.CreateCommand("jobguide")
.Description("shows a link to class guides")
.Parameter("Job")
.Do(async e =>
{
if (e.Args.Length != 1 || string.IsNullOrEmpty(e.Args[0]))
{
await _client.SendMessage(e.Message.Channel, string.Format("Hi {0}, if you would like to see job guides, please say: !job guide [WHM/ DRK, e.t.c.]", e.Message.User));
}
var newsItems = await _botServices.News.GetOrAddNewsItems(new SyndicationSearchFields
{
Type = SyndicationType.JobGuides,
Url = GetJobGuideUrl(e.Args[0]),
Take = 3
});
for (int i = 0; i < newsItems.Count(); i++)
{
await _client.SendMessage(e.Message.Channel, string.Format("\n**{0}.** {1}", i + 1, newsItems.ElementAt(i).ToDiscordMessage()));
}
});
});
}
示例2: Install
public void Install(ModuleManager manager)
{
_client = manager.Client;
_client.UserJoined += async (s, e) =>
{
var buffer = string.Format("Welcome to '{0}', {1}\n\n", e.Server, Mention.User(e.User));
buffer += _client.Commands().AllCommands.ToDiscordMessage();
await _client.SendPrivateMessage(e.User, buffer);
await _client.SendMessage(e.Server.DefaultChannel, string.Format("A wild {0} appears!", Mention.User(e.User)));
};
_client.UserLeft += async (s, e) =>
{
await _client.SendMessage(e.Server.DefaultChannel, string.Format("See you soon, {0}!", Mention.User(e.User)));
};
_client.ChannelUpdated += async (s, e) =>
{
if (_botServices.Server.ChannelTopicUpdated(e.Channel))
{
await _client.SendMessage(e.Channel, string.Format("**Topic Updated**\n'{0}'", e.Channel.Topic));
}
};
/*_client.UserPresenceUpdated += async (s, e) =>
{
if (_botServices.Server.UserHasReturned(e.Server, e.User))
{
//await _client.SendMessage(e.Server.DefaultChannel, string.Format("Welcome back, {0}!", Mention.User(e.User)));
}
};*/
_client.ChannelCreated += async (sender, e) =>
{
await _client.SendMessage(e.Server.DefaultChannel, string.Format("**New Channel Created**\n{0}", Mention.Channel(e.Channel)));
};
_client.MessageReceived += async (s, e) =>
{
if (e.Message.IsAuthor)
return;
var reply = _botServices.AI.GetReply(e.Message.Channel, e.Message);
if(!string.IsNullOrEmpty(reply))
{
await _client.SendMessage(e.Message.Channel, reply);
}
};
_botServices.Ticker.OnTicked += async (s, e) =>
{
if (_botServices.Ticker.TicksElapsed(e.Ticks, 240))
{
await Announce(e);
}
};
}
示例3: handleTiroCommands
internal async static Task handleTiroCommands(MessageEventArgs e, DiscordClient client, Channel currentChannel)
{
switch(e.Message.Text)
{
case "-touhou":
await client.SendMessage(currentChannel, "is THAT another TOUHOU map???");
break;
case "!r":
await client.SendMessage(currentChannel, getTillerinoText(e.Message.User.Id));
break;
default:
break;
}
}
示例4: Install
public void Install(ModuleManager manager)
{
_client = manager.Client;
_client.MessageReceived += async (s, e) =>
{
if (e.Message.IsAuthor)
return;
await _botServices.Defence.CheckUserSpamming(e.Message.Channel, e.User, e.Message.Timestamp);
};
_botServices.Defence.OnUserSpamming += async (s, e) =>
{
_botServices.Defence.AddWarning(e.Channel, e.User);
_botServices.Defence.ClearMessages(e.User);
await _client.SendMessage(e.Channel, string.Format("Please don't spam the channel, {0}!", Mention.User(e.User)));
};
_botServices.Defence.OnUserWarned += async (s, e) =>
{
await _botServices.Karma.AdjustKarma(-1, e.Channel, e.User);
if (e.WarningCount >= 2)
{
await MuteUser(e.Channel.Server, e.Channel, e.User, DateTime.Now.AddMinutes(1));
}
};
_botServices.Defence.OnUserPunished += async (s, e) =>
{
switch (e.Punishment.PunishmentType)
{
case PunishmentType.Mute:
await _client.SendMessage(e.Punishment.Channel, string.Format("{0} has been muted for {1} minutes!", Mention.User(e.Punishment.User), (e.Punishment.ExpiresOn - DateTime.Now).Minutes));
break;
}
};
_botServices.Ticker.OnTicked += async (s, e) =>
{
var expiredPunishments = _botServices.Defence.GetExpiredPunishments();
if (expiredPunishments.Any())
{
ReviewExpiredPunishments(expiredPunishments);
}
};
}
示例5: Main
static void Main(string[] args)
{
var client = new DiscordClient();
//Display all log messages in the console
client.LogMessage += (s, e) => Console.WriteLine("[{e.Severity}] {e.Source}: {e.Message}");
//Echo back any message received, provided it didn't come from the bot itself
client.MessageReceived += async (s, e) =>
{
if (!e.Message.IsAuthor)
await client.SendMessage(e.Channel, e.Message.Text);
};
//Convert our sync method to an async one and block the Main function until the bot disconnects
client.Run(async () =>
{
//Connect to the Discord server using our email and password
await client.Connect(EMAIL, PASSWORD);
client.SetGame(1);
//If we are not a member of any server, use our invite code (made beforehand in the official Discord Client)
/*
if (!client.AllServers.Any())
await client.AcceptInvite(client.GetInvite(TL_SOKU_INVITE_CODE));
*/
});
}
示例6: Main
static void Main(string[] args)
{
var client = new DiscordClient();
//Display all log messages in the console
client.LogMessage += (s, e) => Console.WriteLine("[{e.Severity}] {e.Source}: {e.Message}");
//Echo back any message received, provided it didn't come from the bot itself
client.MessageReceived += async (s, e) =>
{
if (!e.Message.IsAuthor)
await client.SendMessage(e.Channel, e.Message.Text);
};
//Convert our sync method to an async one and block the Main function until the bot disconnects
client.Run(async () =>
{
while (true)
{
try
{
await client.Connect(EMAIL, PASSWORD);
client.SetGame("Discord.Net);
break;
}
catch (Exception ex)
{
client.LogMessage += (s, e) => Console.WriteLine(String.Concat("Login Failed", ex.Message));
await Task.Delay(client.Config.FailedReconnectDelay);
}
}
});
}
示例7: EchoMessage
private async void EchoMessage(DiscordClient client)
{
client.MessageReceived += async (s, e) =>
{
if (!e.Message.IsAuthor)
await client.SendMessage(e.Channel, e.Message.Text);
};
}
示例8: Install
public void Install(ModuleManager manager)
{
_client = manager.Client;
manager.CreateCommands("", group =>
{
group.CreateCommand("gear")
.Description("shows a link to gear and BiS information about a given job")
.Parameter("Job")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Tools.GetUrlFromCommand(e));
});
group.CreateCommand("garland")
.Description("shows a link to gathering information including node spawns")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Tools.GetUrlFromCommand(e));
});
group.CreateCommand("chocobo")
.Description("shows a link to the chocobo colour calculator")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Tools.GetUrlFromCommand(e));
});
group.CreateCommand("tripletriad")
.Description("shows a link to the Triple Triad deck manager")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Tools.GetUrlFromCommand(e));
});
group.CreateCommand("minions")
.Description("shows a link to a player's minion information")
.Parameter("Forename")
.Parameter("Surname")
.Parameter("Server")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Tools.GetUrlFromCommand(e));
});
group.CreateCommand("minicactpot")
.Description("shows a link to the minicactpot calculator")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Tools.GetUrlFromCommand(e));
});
group.CreateCommand("sightseeing")
.Description("shows a link to the sightseeing log helper")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Tools.GetUrlFromCommand(e));
});
});
}
示例9: Install
public void Install(ModuleManager manager)
{
_client = manager.Client;
manager.CreateCommands("", group =>
{
group.CreateCommand("stats")
.Description("shows some server statistics")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Stats.GetStatistics(e.Server).ToDiscordMessage());
});
});
_client.Connected += (s, e) =>
{
Task.Run(() => _botServices.Server.LoadServerUserData(_client.AllServers));
Task.Run(() => _botServices.Server.LoadServerChannelData(_client.AllServers));
};
}
示例10: Install
public void Install(ModuleManager manager)
{
_client = manager.Client;
manager.CreateCommands("", group =>
{
//group.MinPermissions((int)PermissionLevel.User);
group.CreateCommand("who")
.Description("picks a random online member")
.Do(async e =>
{
var onlineMembers = e.Channel.Members.Where(m => m.Status != UserStatus.Offline);
var random = new Random().Next(0, onlineMembers.Count());
var randomUser = onlineMembers.ElementAt(random);
var message = string.Format("{0}!", Mention.User(randomUser));
await _client.SendMessage(e.Message.Channel, message);
});
group.CreateCommand("help")
.Description("sends a list of commands")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _client.Commands().AllCommands.ToDiscordMessage());
});
group.CreateCommand("uptime")
.Description("shows how long the bot has been online for")
.Do(async e =>
{
var difference = DateTime.Now.Subtract(_botServices.Ticker.ConnectedOn);
var message = string.Format("I've been online for **{0}** days, **{1}** hours & **{2}** minutes.", difference.Days, difference.Hours, difference.Minutes);
await _client.SendMessage(e.Message.Channel, message);
});
// https://discordapp.com/invite/0LOWyaMvOUdtZuYL VK
group.CreateCommand("join")
.Description("requests the bot to join another server.")
.Parameter("invite url")
.Do(async e =>
{
var invite = await _client.GetInvite(e.Args[0]);
if (invite.IsRevoked)
{
return;
}
await _client.AcceptInvite(invite);
});
group.CreateCommand("leave")
.Description("instructs the bot to leave this server.")
.Do(async e =>
{
await _client.SendMessage(e.Channel, $"Leaving~");
//await _client.LeaveServer(e.Server);
});
});
_client.MessageReceived += (s, e) =>
{
if (e.Message.IsAuthor)
return;
if (!e.Message.Text.StartsWith("!"))
{
_botServices.Events.AddEvent(e.Message.Server, e.Message.Channel, e.Message.User, EventType.Message);
}
if (e.Message.MentionedUsers.Any())
{
foreach(var mentionedUser in e.Message.MentionedUsers)
{
if (!Equals(mentionedUser, e.Message.User))
{
_botServices.Events.AddEvent(e.Message.Server, e.Message.Channel, mentionedUser, EventType.Mention);
}
}
}
};
}
示例11: handleSimpleCommands
private static async Task<bool> handleSimpleCommands(MessageEventArgs e, DiscordClient client, Channel currentChannel)
{
switch (e.Message.Text)
{
case "-waifu":
await client.SendMessage(currentChannel, "KokoroBot is your waifu now.");
break;
case "-brainpower":
await client.SendMessage(currentChannel, "Huehuehue.");
await client.SendMessage(currentChannel, "You know...");
await client.SendMessage(currentChannel, @">youtube https://www.youtube.com/watch?v=0bOV4ExHPZY");
break;
case "-praise":
await client.SendMessage(currentChannel, "ALL PRAISE KARD (/O.o)/");
break;
case "-part":
await client.SendMessage(currentChannel, "part is the baka who created this bot.");
break;
case "-amazing":
await client.SendMessage(currentChannel, "Amazing \nAmazing \nAmazing \nAmazing \nAmazing");
break;
case "-??":
await client.SendMessage(currentChannel, "??\n??\n??\n??\n??\n??\n??\n??\n??");
break;
case "-sayo":
await client.SendMessage(currentChannel, sayoFacts());
break;
default:
return false;
}
return true;
}
示例12: 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];
//.........这里部分代码省略.........
示例13: 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)
//.........这里部分代码省略.........
示例14: GetRoll
/// <summary>
/// Command variant of GetRoll - Rolls all dice mentioned and posts the result.
/// </summary>
/// <param name="_client">Client to post through.</param>
/// <param name="e">Message events for the command</param>
/// <param name="message">The message to try to compute.</param>
async static void GetRoll(DiscordClient _client, CommandEventArgs e, string message)
{
while (true)
{
string currentRoll = "";
double rollsValue = 0;
List<string> DiceRolls = new List<string>();
try
{
//int index1 = message.IndexOf("[[");
//if (index1 == -1)
// break;
//int index2 = message.IndexOf("]]");
//if (index2 == -1)
// break;
//currentRoll = message.Substring(index1 + 2, index2 - index1 - 2).ToLower();
currentRoll = message;
//message = message.Remove(0, index2 + 2);
try
{
rollsValue = Roll(currentRoll, DiceRolls);
}
catch (Exception ex)
{
await _client.SendMessage(e.Channel, $"Failed to roll: {ex.Message}");
return;
}
}
catch (Exception ex)
{
await _client.SendMessage(e.Channel, "Failed to roll");
return;
}
///await _client.SendMessage(e.Channel, Format.Italics($"Rolling for {e.User.Name}:") + $"`({currentRoll})` \n```{rollsValue} ({rolls}```");
try
{
string rolls = "";
foreach (string str in DiceRolls)
{
if (str == ")" || str == "(")
rolls += str + " ";
else
rolls += "[" + str + "] ";
}
if (rolls == "")
{
rolls = "No dice rolled.";
}
else
{
rolls = rolls.Remove(rolls.Length - 1);
}
await _client.SendMessage(e.Channel, $"Rolling {currentRoll} for {Mention.User(e.User)}\n```{rollsValue} ({rolls})```");
break;
}
catch (Discord.HttpException ex)
{
Console.WriteLine($"Could not post in channel roll was in for some reason. {e.User.Name}, {e.Channel.Name}, {e.Server.Name}");
}
}
}
示例15: Install
public void Install(ModuleManager manager)
{
_client = manager.Client;
manager.CreateCommands("", group =>
{
group.CreateCommand("ranks")
.Description("shows a list of ranks")
.Do(async e =>
{
await _client.SendMessage(e.Message.Channel, _botServices.Karma.Ranks.ToDiscordMessage());
});
group.CreateCommand("rank")
.Description("shows your current rank")
.Do(async e =>
{
var message = string.Empty;
var rank = _botServices.Karma.GetRank(e.User);
if (rank == null || rank.RequiredKarma == 0)
{
message = string.Format("You do not have any karma, {0}", Mention.User(e.Message.User));
await _client.SendMessage(e.Message.Channel, message);
return;
}
var karma = _botServices.Karma.GetKarma(e.User);
message = string.Format("You have {0} karma. Rank: **{1}**.", karma.Amount, rank.Name);
await _client.SendMessage(e.Message.Channel, message);
});
group.CreateCommand("karma")
.Description("gives karma to another member")
.Parameter("@User")
.Do(async e =>
{
await _botServices.Karma.AdjustKarma(1, e.Channel, e.Message.MentionedUsers.ElementAt(0), e.Message.User);
});
});
_botServices.Karma.OnKarmaChanged += async (s, e) =>
{
if (e.Amount > 0)
{
await _client.SendMessage(e.Channel, string.Format("{0} gave karma to {1}!", Mention.User(e.FromUser), Mention.User(e.ToUser)));
}
else
{
await _client.SendMessage(e.Channel, string.Format("{0} has lost karma!", Mention.User(e.ToUser)));
}
};
_botServices.Karma.OnRankChanged += async (s, e) =>
{
var message = (e.NewRank.RequiredKarma < 0)
? "has been demoted to:"
: "has been promoted to a new rank:";
await _client.SendMessage(e.Channel, string.Format("{0} {1} **{2}**", Mention.User(e.User), message, e.NewRank.Name));
};
_botServices.AI.OnBadMessageReceived += async (s, e) =>
{
await _botServices.Karma.AdjustKarma(-1, e.Channel, e.User);
};
_botServices.AI.OnThankfulMessageReceived += async (s, e) =>
{
await _botServices.Karma.AdjustKarma(1, e.Channel, e.ToUser, e.FromUser);
};
}