InteractiveService not found
I added the NuGet package to my project and linked everything up, and upon trying to start the bot I get an error message saying "dependency"InteractiveService" was not found. I came over here to use the Github version, and the same issue came up. Is there any way to fix this?
Same issue :/
Hi there,
It is working for me. Maybe I can be of assistant.
How are you Linking it up?
Simply adding an InteractiveService to the ServiceCollection, and then inheriting InteractiveBase in one of my command modules.
_services = new ServiceCollection() // Microsoft.Extensions.DependencyInjection
.AddSingleton(_client)
.AddSingleton(_commands)
.AddSingleton<CommandHandler>();
//.AddSingleton<InteractiveService>()
using System;
using System.Threading.Tasks;
using Discord.Addons.Interactive;
using Discord.Commands;
// https://github.com/foxbot/Discord.Addons.Interactive/tree/master/SampleApp
namespace HSBot.Modules
{
public class SampleModule : InteractiveBase
{
Okay, please try the following:
_services = new ServiceCollection() // Microsoft.Extensions.DependencyInjection .AddSingleton(_client) .AddSingleton(_commands) .AddSingleton<CommandHandler>(); .AddSingleton(new InteractiveService(_client))
After some further poking around, I fixed my issue! I was simply using an IServiceCollection rather than an IServiceProvider. Thank you for helping me, I probably wouldn't have looked further if it weren't for it. :)
Actually I spoke too soon, for some reason when I execute a command in a module that implements InteractiveBase, it spits out "Failed to create "HSBot.Modules.SampleModule", dependency "InteractiveService" was not found." I'm implementing it in my main like this:
_services = new ServiceCollection() // Microsoft.Extensions.DependencyInjection
.AddSingleton(_client)
.AddSingleton(_commands)
.AddSingleton<CommandHandler>()
.AddSingleton<InteractiveService>()
.BuildServiceProvider();
Arh yes, it has to be a ServiceProvider. Could you try building it like this:
_services = new ServiceCollection() // Microsoft.Extensions.DependencyInjection .AddSingleton(_client) .AddSingleton(_commands) .AddSingleton<CommandHandler>() .AddSingleton(new InteractiveService(client)) .BuildServiceProvider();
Correction for your client variable name (sorry):
_services = new ServiceCollection() // Microsoft.Extensions.DependencyInjection .AddSingleton(_client) .AddSingleton(_commands) .AddSingleton() .AddSingleton(new InteractiveService(_client)) .BuildServiceProvider();
Having the same problem.
System.InvalidOperationException: 'Failed to create "DiscordBot.Modules.UtilityModule", dependency "InteractiveService" was not found.'
class Program
{
static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
private IServiceProvider ConfigureServices()
{
return new ServiceCollection()
// Base
.AddSingleton(_client)
.AddSingleton<CommandService>()
.AddSingleton<CommandHandlingService>()
.AddSingleton<InteractiveService>(new InteractiveService(_client))
// Logging
.AddLogging()
.AddSingleton<LogService>()
// Extra
.AddSingleton(Config)
// Add additional services here...
.BuildServiceProvider();
}
...
using Discord;
using Discord.Commands;
using Discord.Addons.Interactive;
using Discord.WebSocket;
namespace DiscordBot.Modules
{
[Name("Utility")]
public class UtilityModule : InteractiveBase
Have also tried
.AddSingleton<InteractiveService>()
Project only compiles when I change UtilityModule.cs to inherit from ModuleBase<SocketCommandContext>, and that's not what I want to do.
Edit: and the sample project works perfectly, but I'm not able to find the discrepancy.
Edit2: Found the problem in CommandHandlingService.cs
public async Task InitializeAsync(IServiceProvider provider)
{
_provider = provider;
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), services: --->null<---);
// Add additional initialization code here...
}
This issue still exists
For all the people still having this issue I (might have) found a solution:
Be sure to not only add the services in AddModulesAsync, but also in the ExecuteAsync. LOL
_services = new ServiceCollection().
AddSingleton(_client).
AddSingleton<InteractiveService>().
BuildServiceProvider();
CommandService.AddModulesAsync(assembly: Assembly.GetEntryAssembly(), services: _services);
await CommandService.ExecuteAsync(context, argPos, _services);