开发者

Discord.Net | Why won't my last command register?

This is my program.cs file and obviously the token is actually in there.

using System;
using System.Reflection;
using System.Threading.Tasks;
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using IResult = Discord.Interactions.IResult;

namespace StorytimeBot.v2
{
    class Program
    {
        static void Main(string[] args) => new Program().RunBotAsync().GetAwaiter().GetResult();

        private DiscordSocketClient _client;
        private InteractionService _commands;
        private IServiceProvider _services;

        public async Task RunBotAsync()
        {
            _client = new DiscordSocketClient();
            _commands = new InteractionService(_client.Rest);

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

            string token = "xxxxxxx";

            _client.Log += _client_Log;

            await RegisterCommandsAsync();

            await _client.LoginAsync(TokenType.Bot, token);

            await _client.StartAsync();

            await Task.Delay(-1);
        }

        private Task _client_Log(LogMessage arg)
        {
            Console.WriteLine(arg);
            return Task.CompletedTask;
        }

        public async Task RegisterCommandsAsync()
        {
            await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
            _client.InteractionCreated += HandleInteraction;
            _commands.SlashCommandExecuted += SlashCommandExecuted;
        }

        private Task SlashCommandExecuted(SlashCommandInfo arg1, IInteractionContext arg2, IResult arg3)
        {
            return Task.CompletedTask;
        }

        private async Task HandleInteraction(SocketInteraction arg)
        {
            try
            {
                // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules
                var ctx = new SocketInteractionContext(_client, arg);
                await _commands.ExecuteCommandAsync(ctx, _services);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original
                // response, or at least let the user know that something went wrong during the command execution.
                if (arg.Type == InteractionType.ApplicationCommand)
                    await arg.GetOriginalResponseAsync().ContinueWith(async (msg) => await msg.Result.DeleteAsync());
            }
        }
    }
}

This is a snippet of my commands.cs file and the last command won't register since I added it days ago. My other commands got registered using the same code so I have no idea

public class Commands : InteractionModuleBase<SocketInteractionContext>
    {
[SlashCommand("pointcalc", "Battle Point Calculator!")]
        public async Task PointCalc(int charisma, int wisdom, int intelligence, int armySizeDifference, int conscripts, int armsMen, int cavalry, int knights, bool beingSieged)
        {
            int armySizeAdv = (armySizeDifference % 20) * 1;
            double conscriptsP = conscripts * -.1;
            double armsMenP = armsMen * -.01;
            double cavalryP = cavalry * .1;
            double knightsP = knights * .25;
            in开发者_如何学Pythont beingSiegedP = 0;
            if (beingSieged == true)
            {
                beingSiegedP = 5;
            }

            double battlePoints = charisma + wisdom + (intelligence * 2) + armySizeAdv + conscriptsP + armsMenP + cavalryP + knightsP + beingSiegedP;
            await RespondAsync($"{battlePoints}");
        }

I'm just really lost on the whole thing not being synched up when my other commands synched instantly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜