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


C# Channel.SafeSendMessage方法代码示例

本文整理汇总了C#中Discord.Channel.SafeSendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.SafeSendMessage方法的具体用法?C# Channel.SafeSendMessage怎么用?C# Channel.SafeSendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Discord.Channel的用法示例。


在下文中一共展示了Channel.SafeSendMessage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: JoinInvite

        public static async Task JoinInvite(string inviteId, Channel callback)
        {
            Invite invite = await callback.Client.GetInvite(inviteId);
            if (invite == null)
            {
                await callback.SafeSendMessage("Invite not found.");
                return;
            }
            if (invite.IsRevoked)
            {
                await
                    callback.SafeSendMessage("This invite has expired or the bot is banned from that server.");
                return;
            }

            await invite.Accept();
            await callback.SafeSendMessage("Joined server.");
            await Config.Owner.SendPrivate($"Joined server: `{invite.Server.Name}`.");
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:19,代码来源:Utils.cs

示例3: VerifyFindModule

        private async Task<ModuleManager> VerifyFindModule(string id, Channel callback, bool useCallback = true)
        {
            ModuleManager module = GetModule(id);
            if (module == null)
            {
                if (useCallback)
                    await callback.SafeSendMessage("Unknown module");
                return null;
            }

            if (module.FilterType == ModuleFilter.None ||
                module.FilterType == ModuleFilter.AlwaysAllowPrivate)
            {
                if (useCallback)
                    await callback.SafeSendMessage("This module is global and cannot be enabled/disabled.");
                return null;
            }

            return module;
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:20,代码来源:ModulesModule.cs

示例4: RemoveAutoRoleAssigner

        private async Task RemoveAutoRoleAssigner(ulong serverId, Channel callback, bool shouldCallback = true)
        {
            ulong ignored;
            _joinedRoleSubs.TryRemove(serverId, out ignored);

            if (shouldCallback)
                await callback.SafeSendMessage("Removed auto role assigner for this server.");
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:8,代码来源:AnnouncementModule.cs

示例5: PrintUserInfo

        private async Task PrintUserInfo(User user, Channel textChannel)
        {
            if (user == null)
            {
                await textChannel.SafeSendMessage("User not found.");
                return;
            }

            StringBuilder builder = new StringBuilder("**User info:\r\n**```");
            builder.AppendLine($"- Name: {user.Name} ({user.Discriminator})");
            builder.AppendLine($"- Id: {user.Id}");
            builder.AppendLine($"- Avatar: {user.AvatarUrl}");
            builder.AppendLine($"- Joined: {user.JoinedAt} ");
            await textChannel.SafeSendMessage($"{builder}```");
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:15,代码来源:InfoModule.cs

示例6: Subscribe

        private async Task Subscribe(string twitchChannel, Channel discordChannel)
        {
            if (!_twitch.IsConnected)
                await TwitchTryConnect();

            // normalize channel name.
            twitchChannel = TwitchBot.NormalizeChannelName(twitchChannel);

            // if the twitch bot is not in the twitch channel, tell it to join it.
            if (!_twitch.Channels.Contains(twitchChannel))
                _twitch.JoinChannel(twitchChannel);

            // if there is no entry in _relays for the twitch channel, create one.
            if (!_relays.ContainsKey(twitchChannel))
            {
                List<JsonChannel> channel = new List<JsonChannel> {discordChannel};
                _relays.Add(twitchChannel, channel);
                return;
            }

            // reference the list of channels found by the twitch channel key so we dont have to look it up every time.
            List<JsonChannel> subRef = _relays[twitchChannel];

            // check if the discord channel is already subscribed to the twitch channel.
            if (subRef.FirstOrDefault(c => c.Channel.Id == discordChannel.Id) != null)
                return;

            // add the discord channel to the twitch channel subscribers list.
            subRef.Add(discordChannel);

            await discordChannel.SafeSendMessage($"Subscribed to twitch chat: {twitchChannel}");
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:32,代码来源:TwitchRelayModule.cs

示例7: Unsubscribe

        private async Task Unsubscribe(string twitchChannel, Channel discordChannel)
        {
            // normalize channel name.
            twitchChannel = TwitchBot.NormalizeChannelName(twitchChannel);

            // dont try to remove from a list of subscribers in a twitch channel if we dont even have the channel in the relays list.
            if (!_relays.ContainsKey(twitchChannel)) return;

            // if the twitch relay discord connected channel list doesn't include the discord channel that
            // is passed as the argument, return. We don't want to try to delete something that doesn't exist.
            if (_relays[twitchChannel].FirstOrDefault(c => c.Channel.Id == discordChannel.Id) == null) return;

            // Remove all of the channels in the twitchChannel entry which have the same id as the
            // discord channel that we passed in the arguments
            _relays[twitchChannel].RemoveAll(match => match.Channel.Id == discordChannel.Id);

            // we will command the twitch bot to disconnect from the twitch channel if no
            // discord channel is connected to it.
            if (!_relays[twitchChannel].Any())
                _twitch.PartChannel(twitchChannel);

            await discordChannel.SafeSendMessage($"Unsubscribed from twitch chat: {twitchChannel}");
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:23,代码来源:TwitchRelayModule.cs

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