/// <summary> /// Enables CommandsNext module on this <see cref="DiscordClient"/>. /// </summary> /// <param name="client">Client to enable CommandsNext for.</param> /// <param name="cfg">CommandsNext configuration to use.</param> /// <returns>Created <see cref="CommandsNextExtension"/>.</returns> public static CommandsNextExtension UseCommandsNext(this DiscordClient client, CommandsNextConfiguration cfg) { if (client.GetExtension <CommandsNextExtension>() != null) { throw new InvalidOperationException("CommandsNext is already enabled for that client."); } if (client.Configuration.Intents.HasValue) { if (!Utilities.HasMessageIntents(client.Configuration.Intents)) { client.Logger.LogCritical(CommandsNextEvents.Intents, "The CommandsNext extension is registered but there are no message intents enabled. It is highly recommended to enable them."); } if (!client.Configuration.Intents.Value.HasIntent(DiscordIntents.Guilds)) { client.Logger.LogCritical(CommandsNextEvents.Intents, "The CommandsNext extension is registered but the guilds intent is not enabled. It is highly recommended to enable it."); } } var cnext = new CommandsNextExtension(cfg); client.AddExtension(cnext); return(cnext); }
public DiscordService(DiscordClient client, IServiceProvider serviceProvider, ILogger <DiscordService> logger) { m_discordClient = client; m_logger = logger; var commands = m_discordClient.UseCommandsNext(new CommandsNextConfiguration { EnableDms = false, Services = serviceProvider, UseDefaultCommandHandler = false, }); m_discordClient.UseInteractivity(new InteractivityConfiguration() { }); commands.RegisterConverter(new EnumConverter <RoleKind>()); commands.RegisterConverter(new EnumConverter <WowFaction>()); commands.RegisterCommands(GetType().Assembly); commands.RegisterConverter(new QualifiedWowCharacterConverter()); commands.RegisterConverter(new UserWowCharacterConverter()); commands.RegisterConverter(new WowCharacterConverter()); commands.RegisterConverter(new WowClassConverter()); commands.RegisterConverter(new WowItemConverter()); commands.RegisterConverter(new WowItemsConverter()); commands.RegisterConverter(new WowItemRecipeConverter()); commands.RegisterConverter(new WowProfessionConverter()); commands.RegisterConverter(new WowServerConverter()); client.AddExtension(new HandlersExtension()); client.GetExtension <HandlersExtension>().RegisterHandlers(typeof(Program).Assembly); }
/// <summary> /// Creates a new VoiceNext client with specified settings. /// </summary> /// <param name="client">Discord client to create VoiceNext instance for.</param> /// <param name="config">Configuration for the VoiceNext client.</param> /// <returns>VoiceNext client instance.</returns> // Token: 0x06000012 RID: 18 RVA: 0x00002268 File Offset: 0x00000468 public static VoiceNextExtension UseVoiceNext(this DiscordClient client, VoiceNextConfiguration config) { if (client.GetExtension <VoiceNextExtension>() != null) { throw new InvalidOperationException("VoiceNext is already enabled for that client."); } VoiceNextExtension voiceNextExtension = new VoiceNextExtension(config); client.AddExtension(voiceNextExtension); return(voiceNextExtension); }
public static InteractivityExtension UseInteractivity(this DiscordClient c, InteractivityConfiguration cfg) { if (c.GetExtension <InteractivityExtension>() != null) { throw new Exception("Interactivity module is already enabled for this client!"); } var m = new InteractivityExtension(cfg); c.AddExtension(m); return(m); }
/// <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) { if (client.GetExtension <SlashCommandsExtension>() != null) { throw new InvalidOperationException("Slash commands are already enabled for that client."); } var scomm = new SlashCommandsExtension(); client.AddExtension(scomm); return(scomm); }
/// <summary> /// Enables CommandsNext module on this <see cref="DiscordClient"/>. /// </summary> /// <param name="client">Client to enable CommandsNext for.</param> /// <param name="cfg">CommandsNext configuration to use.</param> /// <returns>Created <see cref="CommandsNextExtension"/>.</returns> public static CommandsNextExtension UseCommandsNext(this DiscordClient client, CommandsNextConfiguration cfg) { if (client.GetExtension <CommandsNextExtension>() != null) { throw new InvalidOperationException("CommandsNext is already enabled for that client."); } var cnext = new CommandsNextExtension(cfg); client.AddExtension(cnext); return(cnext); }
public static MusicExtension UseMusic(this DiscordClient c) { if (c.GetExtension <MusicExtension>() != null) { throw new Exception("Music module is already enabled for this client!"); } var m = new MusicExtension(); c.AddExtension(m); return(m); }
/// <summary> /// Creates a new Lavalink client with specified settings. /// </summary> /// <param name="client">Discord client to create Lavalink instance for.</param> /// <returns>Lavalink client instance.</returns> public static LavalinkExtension UseLavalink(this DiscordClient client) { if (client.GetExtension <LavalinkExtension>() != null) { throw new InvalidOperationException("Lavalink is already enabled for that client."); } var lava = new LavalinkExtension(); client.AddExtension(lava); return(lava); }
/// <summary> /// Enables interactivity for this <see cref="DiscordClient"/> instance. /// </summary> /// <param name="client">The client to enable interactivity for.</param> /// <param name="configuration">A configuration instance. Default configuration values will be used if none is provided.</param> /// <returns>A brand new <see cref="InteractivityExtension"/> instance.</returns> /// <exception cref="InvalidOperationException">Thrown if interactivity has already been enabled for the client instance.</exception> public static InteractivityExtension UseInteractivity(this DiscordClient client, InteractivityConfiguration configuration = null) { if (client.GetExtension <InteractivityExtension>() != null) { throw new InvalidOperationException($"Interactivity is already enabled for this {(client._isShard ? "shard" : "client")}."); } configuration ??= new InteractivityConfiguration(); var extension = new InteractivityExtension(configuration); client.AddExtension(extension); return(extension); }
/// <summary> /// Creates a new Lavalink client with specified settings. /// </summary> /// <param name="client">Discord client to create Lavalink instance for.</param> /// <returns>Lavalink client instance.</returns> public static LavalinkExtension UseLavalink(this DiscordClient client) { if (client.GetExtension <LavalinkExtension>() != null) { throw new InvalidOperationException("Lavalink is already enabled for that client."); } if (!client.Configuration.Intents.HasIntent(DiscordIntents.GuildVoiceStates)) { client.Logger.LogCritical(LavalinkEvents.Intents, "The Lavalink extension is registered but the guild voice states intent is not enabled. It is highly recommended to enable it."); } var lava = new LavalinkExtension(); client.AddExtension(lava); return(lava); }
public Bot() { if (!File.Exists(CONFIG_PATH)) { new Config().SaveToFile(CONFIG_PATH); Console.WriteLine($"{CONFIG_PATH} not found, new one has been generated. Please fill in your info"); return; } Config = Config.LoadFromFile(CONFIG_PATH); // setup discord client _client = new DiscordClient(new DiscordConfiguration() { Token = Config.Token, TokenType = TokenType.Bot, AutoReconnect = true, GatewayCompressionLevel = GatewayCompressionLevel.Stream, }); // setup commands _commands = _client.UseCommandsNext(new CommandsNextConfiguration() { StringPrefixes = new string[] { Config.Prefix }, CaseSensitive = false, EnableDms = true, EnableDefaultHelp = false, }); // setup interactivity _interactivity =_client.UseInteractivity(new InteractivityConfiguration() { Timeout = TimeSpan.FromSeconds(30) }); // setup voice _voice = _client.UseVoiceNext(new VoiceNextConfiguration() { EnableIncoming = false, }); // setup custom extensions _client.AddExtension(new BotContextExtension(this)); _client.AddExtension(new EmojiExtension()); _client.AddExtension(new DownloaderExtension()); _client.AddExtension(new BooruExtension()); _client.AddExtension(new ConverterExtension()); _client.AddExtension(new SoundEffectWatcherExtension("./soundEffects")); _client.AddExtension(new YoutubeAPIExtension(Config.GoogleApiKey)); // setup custom converters _commands.RegisterConverter(new RegionConverter()); // hook events _client.Ready += Client_Ready; _client.SocketOpened += Client_SocketOpened; _client.SocketClosed += Client_SocketClosed; _client.SocketErrored += Client_SocketErrored; _client.ClientErrored += Client_ClientError; _commands.CommandExecuted += Commands_CommandExecuted; _commands.CommandErrored += Commands_CommandErrored; // add commands _commands.RegisterCommands(Assembly.GetExecutingAssembly()); }