/// <summary>
        /// Enables slash commands on this <see cref="DiscordClient"/>
        /// </summary>
        /// <param name="client">Client to enable slash commands for</param>
        /// <param name="config">Configuration to use</param>
        /// <returns>Created <see cref="SlashCommandsExtension"/></returns>
        public static SlashCommandsExtension UseSlashCommands(this DiscordClient client,
                                                              SlashCommandsConfiguration config = null)
        {
            if (client.GetExtension <SlashCommandsExtension>() != null)
            {
                throw new InvalidOperationException("Slash commands are already enabled for that client.");
            }

            var scomm = new SlashCommandsExtension(config);

            client.AddExtension(scomm);
            return(scomm);
        }
Exemplo n.º 2
0
 internal SlashCommandsExtension(SlashCommandsConfiguration configuration)
 {
     _configuration = configuration;
 }
        /// <summary>
        /// Enables slash commands on this <see cref="DiscordShardedClient"/>.
        /// </summary>
        /// <param name="client">Client to enable slash commands on.</param>
        /// <param name="config">Configuration to use.</param>
        /// <returns>A dictionary of created <see cref="SlashCommandsExtension"/> with the key being the shard id.</returns>
        public static async Task <IReadOnlyDictionary <int, SlashCommandsExtension> > UseSlashCommandsAsync(this DiscordShardedClient client, SlashCommandsConfiguration config = null)
        {
            var modules = new Dictionary <int, SlashCommandsExtension>();

            await(Task) client.GetType().GetMethod("InitializeShardsAsync", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(client, null);
            foreach (var shard in client.ShardClients.Values)
            {
                var scomm = shard.GetSlashCommands();
                if (scomm == null)
                {
                    scomm = shard.UseSlashCommands(config);
                }

                modules[shard.ShardId] = scomm;
            }

            return(modules);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Enables slash commands on this <see cref="DiscordShardedClient"/>.
        /// </summary>
        /// <param name="client">Client to enable slash commands on.</param>
        /// <param name="config">Configuration to use.</param>
        /// <returns>A dictionary of created <see cref="SlashCommandsExtension"/> with the key being the shard id.</returns>
        public static async Task <IReadOnlyDictionary <int, SlashCommandsExtension> > UseSlashCommandsAsync(this DiscordShardedClient client, SlashCommandsConfiguration config = null)
        {
            var modules = new Dictionary <int, SlashCommandsExtension>();
            await client.InitializeShardsAsync();

            foreach (var shard in client.ShardClients.Values)
            {
                var scomm = shard.GetSlashCommands();
                if (scomm == null)
                {
                    scomm = shard.UseSlashCommands(config);
                }

                modules[shard.ShardId] = scomm;
            }

            return(modules);
        }