本文整理汇总了C#中Discord.Channel.DownloadMessages方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.DownloadMessages方法的具体用法?C# Channel.DownloadMessages怎么用?C# Channel.DownloadMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.Channel
的用法示例。
在下文中一共展示了Channel.DownloadMessages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMessages
/// <summary>
/// Get a number of messages from a channel.
/// </summary>
/// <param name="c">The channel</param>
/// <param name="numReq">The number of messages requested</param>
/// <returns></returns>
public static async Task<IEnumerable<Message>> GetMessages(Channel c, int numReq)
{
int currentCount = 0;
int numToGetThisLoop = 100;
int newMsgCount = 100;
ulong lastMsgId;
IEnumerable<Message> allMsgs = new List<Message>();
IEnumerable<Message> newMsgs = new List<Message>();
if (numReq <= 0) return null; //Quit on bad request
lastMsgId = (await c.DownloadMessages(1))[0].Id; //Start from last message (will be excluded)
while (currentCount < numReq && newMsgCount == numToGetThisLoop) //Keep going while we don't have enough, and haven't reached end of channel
{
if (numReq - currentCount < 100) //If we need less than 100 to achieve required number
numToGetThisLoop = numReq - currentCount; //Reduce number to get this loop
newMsgs = await c.DownloadMessages(numToGetThisLoop, lastMsgId, Relative.Before, false); //Get N messages before that id
newMsgCount = newMsgs.Count(); //Get the count we downloaded, usually 100
currentCount += newMsgCount; //Add new messages to count
lastMsgId = newMsgs.Last().Id; //Get the id to start from on next iteration
allMsgs = allMsgs.Concat(newMsgs); //Add messages to the list
}
return allMsgs;
}