本文整理汇总了C#中IUserMessage.DeleteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IUserMessage.DeleteAsync方法的具体用法?C# IUserMessage.DeleteAsync怎么用?C# IUserMessage.DeleteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserMessage
的用法示例。
在下文中一共展示了IUserMessage.DeleteAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Pick
public async Task Pick(IUserMessage imsg)
{
var channel = (ITextChannel)imsg.Channel;
if (!channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages)
{
await channel.SendMessageAsync("`I need manage channel permissions in order to process this command.`").ConfigureAwait(false);
return;
}
List<IUserMessage> msgs;
try { await imsg.DeleteAsync().ConfigureAwait(false); } catch { }
if (!plantedFlowers.TryRemove(channel.Id, out msgs))
return;
await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);
await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false);
var msg = await channel.SendMessageAsync($"**{imsg.Author.Username}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);
var t = Task.Run(async () =>
{
await Task.Delay(10000).ConfigureAwait(false);
try { await msg.DeleteAsync().ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
});
}
示例2: Iamnot
public async Task Iamnot(IUserMessage umsg, [Remainder] IRole role)
{
var channel = (ITextChannel)umsg.Channel;
var guildUser = (IGuildUser)umsg.Author;
GuildConfig conf;
IEnumerable<SelfAssignedRole> roles;
using (var uow = DbHandler.UnitOfWork())
{
conf = uow.GuildConfigs.For(channel.Guild.Id);
roles = uow.SelfAssignedRoles.GetFromGuild(channel.Guild.Id);
}
SelfAssignedRole roleModel;
if ((roleModel = roles.FirstOrDefault(r => r.RoleId == role.Id)) == null)
{
await channel.SendMessageAsync("💢 That role is not self-assignable.").ConfigureAwait(false);
return;
}
if (!guildUser.Roles.Contains(role))
{
await channel.SendMessageAsync($"❎ You don't have **{role.Name}** role.").ConfigureAwait(false);
return;
}
try
{
await guildUser.RemoveRolesAsync(role).ConfigureAwait(false);
}
catch (Exception)
{
await channel.SendMessageAsync($"⚠️ I am unable to add that role to you. `I can't remove roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false);
return;
}
var msg = await channel.SendMessageAsync($"🆗 You no longer have **{role.Name}** role.").ConfigureAwait(false);
if (conf.AutoDeleteSelfAssignedRoleMessages)
{
var t = Task.Run(async () =>
{
await Task.Delay(3000).ConfigureAwait(false);
try { await msg.DeleteAsync().ConfigureAwait(false); } catch { } // if 502 or something, i don't want bot crashing
try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { }
});
}
}