本文整理汇总了C#中Discord.Channel.CanJoinChannel方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.CanJoinChannel方法的具体用法?C# Channel.CanJoinChannel怎么用?C# Channel.CanJoinChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.Channel
的用法示例。
在下文中一共展示了Channel.CanJoinChannel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanJoinAndTalkInVoiceChannel
public static async Task<bool> CanJoinAndTalkInVoiceChannel(Channel voiceChannel, Channel callback)
{
if (voiceChannel.Type != ChannelType.Voice) throw new ArgumentException(nameof(voiceChannel));
if (callback.Type != ChannelType.Text) throw new ArgumentException(nameof(callback));
if (!voiceChannel.Server.CurrentUser.GetPermissions(voiceChannel).Speak)
{
await callback.SafeSendMessage($"I don't have permission to speak in `{voiceChannel.Name}`.");
return false;
}
if (!voiceChannel.CanJoinChannel(voiceChannel.Server.CurrentUser))
{
await callback.SafeSendMessage($"I don't have permission to join `{voiceChannel.Name}`");
return false;
}
return true;
}
示例2: SafeJoin
/// <summary>
/// Attempts to join a voice channel.
/// </summary>
/// <param name="textCallback">Text callback channel to which we will write when we failed joining the audio channel.</param>
/// <returns>Null if failed joining.</returns>
public static async Task<IAudioClient> SafeJoin(this AudioService audio, Channel voiceChannel,
Channel textCallback)
{
if (voiceChannel.Type != ChannelType.Voice) throw new ArgumentException(nameof(voiceChannel));
if (textCallback.Type != ChannelType.Text) throw new ArgumentException(nameof(textCallback));
if (voiceChannel.CanJoinChannel(voiceChannel.Server.CurrentUser))
{
try
{
return await audio.Join(voiceChannel);
}
catch
{
await textCallback.SafeSendMessage($"Failed joining voice channel `{voiceChannel.Name}`.");
}
}
await textCallback.SafeSendMessage($"I don't have permission to join `{voiceChannel.Name}`.");
return null;
}