示例#1
0
        /// <summary>
        ///     Pre-command execution handling.
        /// </summary>
        private async Task CommandHandleAsync(SocketMessage msgArg)
        {
            // Bail when it's not an user message.
            if (!(msgArg is SocketUserMessage msg))
            {
                return;
            }
            // Also bail if it's a bot message to avoid "certain" situations.
            if (msg.Author.IsBot)
            {
                return;
            }

            int    argPos = 0;
            string prefix = _config.Commands.DefaultPrefix;

            // Checks if the channel is a guild channel, if so, attempts to fetch its prefix.
            if (msg.Channel is SocketGuildChannel guildChannel)
            {
                string guildPrefix = _coreSettings.GetCommandPrefix(guildChannel.Guild);
                if (!string.IsNullOrEmpty(guildPrefix))
                {
                    prefix = guildPrefix;
                }
            }
            if (!msg.HasStringPrefix(prefix, ref argPos))
            {
                return;
            }

            var context = new SocketCommandContext(_client, msg);
            await _commandService.ExecuteAsync(context, argPos, _services).ConfigureAwait(false);
        }