Git Product home page Git Product logo

discord.addons.interactive's Introduction

Interactive

An addon for Discord.Net that adds interactivity to your commands.

Supported Features

  • Waiting for messages over the gateway
  • Paginated messages
  • Reaction callbacks
  • A powerful criteria system

Usage

To use, add an InteractiveService to your service provider. It is also recommended to make your modules inherit from InteractiveBase

discord.addons.interactive's People

Contributors

foxbot avatar joe4evr avatar jyrka98 avatar k-boyle avatar nekzor avatar vasuz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord.addons.interactive's Issues

InteractiveService does not work with DiscordShardedClient

I don't know if this is just me, but trying to use this with a DiscordShardedClient as the client results in the bot not even starting, resulting in the error:
Unhandled Exception: System.InvalidOperationException: Unable to resolve service for type 'Discord.WebSocket.DiscordSocketClient' while attempting to activate 'Discord.Addons.Interactive.InteractiveService'.

I looked at the code and saw that the InteractiveService only used a DiscordSocketClient. I tested the bot with SocketClient instead of ShardedClient and it worked fine. Would there be a way for it to use both Sharded and Socket?

How do I make NextMessageAsync work in slash commands?

Hello, so I wanted to use NextMessageAsync for my bot, but I got problem. It needs something called SocketCommandContext and it does need user and message, but firstly in SocketCommandContext user must be DiscordSocketClient, but SocketClient cannot be converted, secondly you need command message, but slash command is not a messsage, please help!

Paginater Jump button doesn't seem to be working

When I use the jump button it deletes the message I sent with the page number I'd like and sends the stop button emoji as a response - sometimes 1, sometimes 2 - instead of jumping to the desired page. In the image shown I'd typed "2".
image

More customization per paginated page

Similar to how it was done in Discord.Addons.Paginator, it would be nice to be able to add fields to an individual page - instead of using object in the pages list, it would have be a custom class.

Other suggestions would include being able to add an image/thumbnail per page, as well as setting other options, like changing the title, setting the color and changing the author per page.

Update Nuget

The nuget package for this project appears to be three years out of date! Could you push a newer version? Thanks :)

Nextmessageasync doesnt work for DM's with sharding

I dont know if thats related to discord gateways or its interactive bug, but nextmessageasync doesnt work with dm's, it doesnt read dm messages, tested with socket it works fine, but with sharding not, any solution?

Commands not working at all

After applying the sample code to try it out and see how it works, none of the interactive commands seem to work. Even creating a new program and doing a straight copy-paste (changing the bot key of course) does nothing.

Does this feature work with the latest version of .Net or am I missing something?

PagedReplyAsync, Allowing sending embeds.

From my current understanding, PagedReplyAsync will take any object passed to it, and send it's ToString() form. I attempted to get support from the DAPI server, only to be met with this solution:
image
I originally attempted to send a List<Embed>, which paginated the embed's title instead of sending an actual embed. Secondly I tried sending a List<EmbedBuilder>, which obviously just sent the string EmbedBuilder.
image
I don't see any reason why we can't send paged embeds. Thoughts?

Method not found: ....SendMessageAsync.... when calling any Function that sends messages in Chat

I am struggling with the Interactive addon.
If i run any of the Functions that uses the SendMessageAsync() Method it fails and the result.ErrorReason returns:
Method` not found: 'System.Threading.Tasks.Task`1<Discord.Rest.RestUserMessage> Discord.WebSocket.ISocketMessageChannel.SendMessageAsync(System.String, Boolean, Discord.Embed, Discord.RequestOptions)'.

My Module class is defined as public class QuoteModule : InteractiveBase<SocketCommandContext> and i think im am setting up the Services correctly

                _services = new ServiceCollection()
                .AddSingleton(_client)
                .AddSingleton<InteractiveService>()
                .BuildServiceProvider();

            _commands = new CommandService();
            await _commands.AddModulesAsync(
                assembly: Assembly.GetEntryAssembly(),
                services: _services);
            
            _client.MessageReceived += HandleCommandAsync;

Embed Pages

is it possible to use embed and normal strings as pages.

as an example:
pages = [Embed, string, Embed, Embed]

[Feature Suggestion] XML Comments in methods

Hi there,
I downloaded this package and hovered my mouse over some functions and I noticed that there was no comment on what it does, it would be nice if an XML summary was added. That'd be awesome
image
Thanks for reading!

Method not found SendMessageAsync() in .net 5.0

I am getting the below error when trying to send a paginated message to a channel using .net 5.0 and Discord.Net 2.4.0.

I am confused as I thought this was fixed in pull request #34 for issue #33 but I am still seeing the issue in my code. Is there something I am missing?

---> System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task1<Discord.Rest.RestUserMessage> Discord.WebSocket.ISocketMessageChannel.SendMessageAsync(System.String, Boolean, Discord.Embed, Discord.RequestOptions)'. at Discord.Addons.Interactive.PaginatedMessageCallback.DisplayAsync() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Discord.Addons.Interactive.PaginatedMessageCallback.DisplayAsync() at Discord.Addons.Interactive.InteractiveService.SendPaginatedMessageAsync(SocketCommandContext context, PaginatedMessage pager, ICriterion1 criterion)

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?

None of the commands in the InteractiveBase class is working

Hi, I've been trying to use this but none of the discord commands in the class seem to work (such as ReplyAsync and NextMessageAsync. All of them throw a Exception thrown: 'System.NullReferenceException' in mscorlib.dll exception when trying to be used. I checked this as the bot never reaches log.Info(response.ToString());.

Here's some of the code I'm using:

Program.cs

_services = new ServiceCollection()
                .AddSingleton(_client)
                .AddSingleton(_commands)
                .AddSingleton<InteractiveService>()
                .BuildServiceProvider();

InteractionClass.cs:

using System;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.Addons.Interactive;

namespace EimiBot2.Modules
{
    public class InteractionClass : InteractiveBase
    {
        private Logger log = new Logger();

        public async Task GetConfirmation(string replyMessage)
        {
            int next = 0;
            while (next < 5)
            {
                await ReplyAsync(replyMessage);
                var response = await NextMessageAsync();
                
                log.Info(response.ToString());

                if (response != null || response.ToString() != "")
                {
                    if (response.ToString().ToLower() == "yes")
                    {
                        _ = new AdminCommands { ReplyStatus = true };
                        next = 10;

                    }
                    else if (response.ToString().ToLower() == "no")
                    {
                        _ = new AdminCommands { ReplyStatus = false };
                        next = 10;
                    }
                    else
                    {
                        await ReplyAsync("Invalid input. Input one more time.");
                        next++;
                    }
                }
            }

            if (next < 10)
            {
                await ReplyAsync("Invalid inputs. Will close the function.");
                _ = new AdminCommands { ReplyStatus = false };
            }
        }
    }
}

Question about NextMessageAsync

Is there a requirement to call this method from within a Command or within the Command class?

I wrote a small Utilities class in which I implemented the method NextMessageByUserContains(string userID, string message). This is meant to be used for finding replies to a command.

Whenever I call this method from my Command class it results in NullReferences. Then when I move the method over to my Command class it works fine. Is there something I am missing?

Missing method

Hello.

I can't understand. Why I catch this exception?

Part of my code:

                //Before I got List<string> of commands
                try
                {
                    await PagedReplyAsync(pager: new PaginatedMessage
                    {
                        Title = "Instruction",
                        Pages = pages,
                        Color = ColorProvider.GetColorForCurrentGuild(serGuild),
                        Options = new PaginatedAppearanceOptions
                        {
                            Jump = null,
                            Info = null,
                            Stop = null
                        }
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

image

The name 'PagedReplyAsync' does not exist in the current context.

As stated in title. Library was added via NuGet today; attempting to use the pagination module does not seem to be possible due to inability to access the PagedReplyAsync method.

string[] files = Directory.GetFiles(@".\data", "*");
files = files.Select(Path.GetFileName).ToArray();


/* Attempting to test pagination */
var pages = new[] { "Page 1", "Page 2" };


await PagedReplyAsync(pages); // Error comes in here.

The project is using .NET Core 3.1 and hasn't had any problems with Discord.NET. I tried cloning this and manually adding it to the project as a dependency with no results. I also tried rebuilding the .dll myself.

The sample project will, however, load and build. I'm confused.

Interactivity not working

As I could not find a support Discord Server or anything else, I thought I'd ask it here.

As stated, adding the using statement (using Discord.Addons.Interactive;) is not enough, I have to let the class inherit from InteractiveBase. (Otherwise it does not know AT ALL what NextMessageAsync() is/means.)
The only issue I'm facing now is that I inherit ModuleBase<SocketCommandContext> to actually trigger my commands when someone types them in a channel.
I have tried to work only with inheriting InteractiveBase but then my bot does not respond anymore to any command in that class, not even the command I am using the interactivity in.

Am I missing something here? It's 2AM here for me so that is very likely.

Kind regards.

AddReactionCallback

Hi,
I'm working on a project where I want to use AddReactionCallback, I've been looking at the Sample project but couldn't find an example on how to use this.
Is there an example of this and if not, is it possible to create an example on the basic usage and maybe with a custom IReactionCallback class?

System.Threading.Tasks.Task Discord.IUserMessage.RemoveReactionAsync Method not found

Hello, Im using Discord.Addons.Interactive (latest version) and I recently updated to Discord.Net 2.2.0, it seems that the paged messages aren't working anymore. The bot adds the reactions but the ReactionAdded handler is throwing an unhandled exception when I react. Is there a way to fix this?

6:10 PM [Gateway] A ReactionAdded handler has thrown an unhandled exception.
Method not found: 'System.Threading.Tasks.Task Discord.IUserMessage.RemoveReactionAsync(Discord.IEmote, Discord.IUser, Discord.RequestOptions)'.
   at Discord.Addons.Interactive.PaginatedMessageCallback.HandleCallbackAsync(SocketReaction reaction)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Discord.Addons.Interactive.PaginatedMessageCallback.HandleCallbackAsync(SocketReaction reaction)
   at Discord.Addons.Interactive.InteractiveService.HandleReactionAsync(Cacheable`2 message, ISocketMessageChannel channel, SocketReaction reaction)
   at Discord.EventExtensions.InvokeAsync[T1,T2,T3](AsyncEvent`1 eventHandler, T1 arg1, T2 arg2, T3 arg3)
   at Discord.WebSocket.DiscordSocketClient.TimeoutWrap(String name, Func`1 action)
Method not found: 'System.Threading.Tasks.Task Discord.IUserMessage.RemoveReactionAsync(Discord.IEmote, Discord.IUser, Discord.RequestOptions)'.

InteractiveService helpers not working

DI helpers for InteractiveService seem to not work.
Only way I got it to work is using original constructor:

.AddSingleton(new InteractiveService((BaseSocketClient)client))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.