当前位置: 首页>>代码示例>>C#>>正文


C# Channel.CanJoinChannel方法代码示例

本文整理汇总了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;
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:18,代码来源:Utils.cs

示例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;
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:26,代码来源:Extensions.cs


注:本文中的Discord.Channel.CanJoinChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。