Kord-Extensions/kord-extensions

Throws exception, when using translated slash subcommands

Closed this issue · 11 comments

Description

I registered slash subcommand (eg /remind list), but when I used it, bot throwed exception (with translated slash commands works fine)

Exception log:

Exception in thread "DefaultDispatcher-worker-12" java.lang.IllegalStateException: Unknown subcommand: list
    at com.kotlindiscord.kord.extensions.commands.application.slash.SlashCommand.findCommand(SlashCommand.kt:211)
    at com.kotlindiscord.kord.extensions.commands.application.slash.SlashCommand.findCommand(SlashCommand.kt:198)
    at com.kotlindiscord.kord.extensions.commands.application.slash.EphemeralSlashCommand.call(EphemeralSlashCommand.kt:44)
    at com.kotlindiscord.kord.extensions.commands.application.DefaultApplicationCommandRegistry.handle$suspendImpl(DefaultApplicationCommandRegistry.kt:353)
    at com.kotlindiscord.kord.extensions.commands.application.DefaultApplicationCommandRegistry.handle(DefaultApplicationCommandRegistry.kt)
    at com.kotlindiscord.kord.extensions.ExtensibleBot$registerListeners$8.invokeSuspend(ExtensibleBot.kt:177)
    at com.kotlindiscord.kord.extensions.ExtensibleBot$registerListeners$8.invoke(ExtensibleBot.kt)
    at com.kotlindiscord.kord.extensions.ExtensibleBot$registerListeners$8.invoke(ExtensibleBot.kt)
    at com.kotlindiscord.kord.extensions.ExtensibleBot$registerListeners$suspendImpl$$inlined$on$default$17$1.invokeSuspend(ExtensibleBot.kt:243)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
    Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@3a3f17ec, Dispatchers.Default]

Versions

  • kord-core 0.8.0-M14
  • kord-extensions 1.5.4-SNAPSHOT
  • Gradle 7.4.2
  • JDK 17.0.2
  • Kotlin 1.6.20

Code Examples

Not working cmd:

class Reminder : Extension() {
	override val name = "reminder"
	
	override suspend fun setup() {
		ephemeralSlashCommand {
			name = "extensions.reminder.commandName"
			description = "extensions.reminder.commandDescription"
		
			ephemeralSubCommand {
				name = "extensions.reminder.list.commandName"
				description = "extensions.reminder.list.commandDescription"
		
				action {
					// Smart code...
				}
			}
		}
	}
}

Working cmd:

class Info : Extension() {
	override val name = "info"

	override suspend fun setup() {
		publicSlashCommand {
			name = "extensions.info.commandName"
			description = "extensions.info.commandDescription"

			action {
				// Another smart code...
			}
		}
	}
}

strings.properties

extensions.info.commandName = about
extensions.info.commandDescription = Get some info about this server

extensions.reminder.commandName = remind
extensions.reminder.commandDescription = Remind system
extensions.reminder.list.commandName = list
extensions.reminder.list.commandDescription = Shows your reminds list

Hello, and thanks for opening an issue! As this is the first time you've created an issue on this repository, we'd just like to offer you a warm welcome to the project, and the following pointers:

  • Most importantly, all issues must adhere to our Code of Conduct. Please give it a quick read if you haven't already.

  • While our team is passionate about the projects we've created here, we're all volunteers. Please don't be offended if it takes time for us to get to your issue - we'll be here as soonas we can be!

  • Please provide as much information as possible when asking a question, reporting a problem, or submitting a feature request. This will help us to address your issue quickly and efficiently. If you forgot to add some information, no worries - feel free to edit the issue and add anything you missed!

    Thanks for contacting us! If you have any further questions, please feel free to join us on Discord in the #dev-kotdis channel (or #kordex-discussion for Kord Extensions projects), or to contact a staff member directly.

Thanks for that - as this snapshot isn't quite ready for release, I'm taking the opportunity to overhaul how the modules are tested. Once I've done that, I'll get to this!

I've had a look at this with my own translations. I am unable to reproduce this with our simple test extension.

It might be worth removing the spaces either sides of the = in your properties file, but honestly, I'm not sure how to repro this.

I've had a look at this with my own translations. I am unable to reproduce this with our simple test extension.

It might be worth removing the spaces either sides of the = in your properties file, but honestly, I'm not sure how to repro this.

Your test extension doesn't translate sub command names.

The issue is that locally the bot knows the command as but discord knows it as

Root commands don't have that issue, as they use IDs rather than names

The problem here is, the translation keys in the test bot are the same as the translation, so the issue does not happen here

Your observations are correct with the default Discord client, but do not match what I observed while I was using the slash command localization build override that Discord supplies. This build override has now expired, however, so we're stuck for the moment.

image

Here's an image provided by a Chinese user during testing.

Your observations are correct with the default Discord client, but do not match what I observed while I was using the slash command localization build override that Discord supplies. This build override has now expired, however, so we're stuck for the moment.

Your observations are still inaccurate, as Discord only sends the "default locale name" and your example shows the same key as value, whether they differ in other languages is irrelevant, try using the same bundle we used in #162

I've merged the PR - is that the last thing this issue needs?

it should be

Sounds good, then - feel free to drop a comment to reopen if needed!