My commands aren't updating

I've set the defaultGuild on my bot config, when I restart my bot, the commands aren't updated on my guild so I cannot test them.
Solution:
then don't use defaultGuild
Jump to solution
54 Replies
Shaun
ShaunOP5mo ago
God knows what's going on it doesn't even register the commands at all anymore I have to kick my bot and reinvite it every time? Why does it swallow exceptions and print this? How can I see my exceptions? Unfortunately, an error occurred during command processing. Please let a staff member know.
gdude
gdude5mo ago
They'll be in the logs They're not swallowed Make sure you have an SLF4J logging provider set up, eg logback, log4j, slf4j-simple The commands should be updated if they're defined correctly, so my guess is that you're not checking the logs for errors? Or maybe you are? Please confirm
Shaun
ShaunOP5mo ago
Ah I see that's why it was warning about no logger
gdude
gdude5mo ago
yep, you need a logger
Shaun
ShaunOP5mo ago
if defaultGuild is set does it not register the command on other servers at all ? I have a couple of servers I want to test but only the one set as defaultGuild responds, the rest dont respond
gdude
gdude5mo ago
defaultGuild is, well, a default for commands without a guild set, it'll use that, if set if the command has a guild set, it shouldn't use that
Shaun
ShaunOP5mo ago
This is what happens if I don't set the guild as default
No description
Shaun
ShaunOP5mo ago
I see something about an unknown slash command in the logs
gdude
gdude5mo ago
hmm, well, you'll get that log message when a slash command is registered on the Discord API side, but it couldn't be matched to a command you have set up on your bot are you sure the extension containing the command has been added?
Shaun
ShaunOP5mo ago
Yes Because it works on the defaultGuild, I have no logic around adding it conditionally
gdude
gdude5mo ago
hmm can you show me your command definition?
Shaun
ShaunOP5mo ago
which part? omg pls remove that slow mode
publicSlashCommand(::PredictPriceArgs) {
name = "price"
description = "Predicts the price of an item"

action {
val imageArg = arguments.image
val bufferedImage = ImageIO.read(URL(imageArg.url))
val text = tess.doOCR(bufferedImage)

print(text)

val item = try {
parseItemText(text)
} catch (e: IllegalArgumentException) {
respond {
content = "Error: ${e.message}"
}
return@action
}

val price = pricePredictService.estimatePrice(item)

respond {
val attributes = (item.static + item.random)
.map { "**${it.key}**: ${it.value}" }
.joinToString("\n")

val itemInfo = "**Rarity**: ${item.rarity.name.lowercase().capitalize()}\n$attributes"
embed {
title = item.item
description = itemInfo
image = imageArg.url

field {
inline = true
name = "Price"
value = price.price.toString()
}
}
}
}
}
publicSlashCommand(::PredictPriceArgs) {
name = "price"
description = "Predicts the price of an item"

action {
val imageArg = arguments.image
val bufferedImage = ImageIO.read(URL(imageArg.url))
val text = tess.doOCR(bufferedImage)

print(text)

val item = try {
parseItemText(text)
} catch (e: IllegalArgumentException) {
respond {
content = "Error: ${e.message}"
}
return@action
}

val price = pricePredictService.estimatePrice(item)

respond {
val attributes = (item.static + item.random)
.map { "**${it.key}**: ${it.value}" }
.joinToString("\n")

val itemInfo = "**Rarity**: ${item.rarity.name.lowercase().capitalize()}\n$attributes"
embed {
title = item.item
description = itemInfo
image = imageArg.url

field {
inline = true
name = "Price"
value = price.price.toString()
}
}
}
}
}
gdude
gdude5mo ago
right, I see.. and this is without a guild set? so then how did you set the guild at command level?
Shaun
ShaunOP5mo ago
I'm not sure what you mean
gdude
gdude5mo ago
well, your problem is that commands aren't recognised when you try to register them to a guild that isn't the set default guild, right?
Shaun
ShaunOP5mo ago
I thought it registers them globally?
gdude
gdude5mo ago
yes, this looks like a global command to me - though it'll be a guild command if you have a default guild set
Shaun
ShaunOP5mo ago
Not both?
gdude
gdude5mo ago
No, they're different scopes
Shaun
ShaunOP5mo ago
So if I set a defaultGuild then my bot wont work in any other guilds?
gdude
gdude5mo ago
that's the point of that setting, yeah it's mostly useful for testing above all else
Shaun
ShaunOP5mo ago
I want to test in multiple guilds, how can I achieve this?
gdude
gdude5mo ago
though you can override it at the command level well, my question is, what difference are you expecting by using another guild?
Shaun
ShaunOP5mo ago
I want other people to be able to use my bot while its in development, I don't want to invite everyone to my guild
Solution
gdude
gdude5mo ago
then don't use defaultGuild
Shaun
ShaunOP5mo ago
then I have to wait an hour for every change ?
gdude
gdude5mo ago
you shouldn't really be testing with your production bot in the first place the point of defaultGuild is that, when introduced, global commands took up to an hour to update in the client, so you probably wanted to temporarily make them guild commands while testing
Shaun
ShaunOP5mo ago
Ah I see this wasn't developed with cowboy developers in mind lol
gdude
gdude5mo ago
in practise they tend to not actually take that long anymore, though it's worth noting that that delay mostly exists for modifying existing commands, occasionally it matters for creating them but if a command already exists and you just changed the action, it shouldn't change much about the existing command I'm not sure what you mean by cowboy developers lmao, it's generally better not to test in production tho
Shaun
ShaunOP5mo ago
cowboy developers = shit developers that don't follow good practice Like me
gdude
gdude5mo ago
it's not necessarily a bad developer trait lmao it's just not how most people write software
Shaun
ShaunOP5mo ago
I have two modes of development, cowboy mode, when I'm in a new area, and I'm not sure what's going on, then full production mode, when I'm confident enough to write good code I normally write an awful prototype/POC, then rewrite it all when I know it can work
Shaun
ShaunOP5mo ago
This is working great so far
No description
gdude
gdude5mo ago
it's probably worth noting that like, making all commands guild commands on all guilds is.. very intensive on the API you'd get slammed hard by rate limits
Shaun
ShaunOP5mo ago
It's probably in like 5 servers max and registering 1 command
gdude
gdude5mo ago
for now discord has strict rate limits on command reg though
Shaun
ShaunOP5mo ago
Okay I'll bear that in mind
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Shaun
ShaunOP5mo ago
How could I add a global exception handler? To essentially change the Unfortunately, an error occurred during command processing. Please let a staff member know. message
gdude
gdude5mo ago
What would you like to change it to? There's a couple ways to do things here, depending on what you want
Shaun
ShaunOP5mo ago
Is there a global error handler?
gdude
gdude5mo ago
In the JVM sense? No There is a translation string you can override and a formatting function There's also a Sentry integration So, again, what are you trying to do here?
Shaun
ShaunOP5mo ago
Nothing I was just wondering if there was a global exception handler Like the one in spring
gdude
gdude5mo ago
I dunno what spring does, but no, haha
Shaun
ShaunOP5mo ago
They let you do something like this
@ControllerAdvice
class GlobalExceptionHandler {

@ExceptionHandler(Exception::class)
fun handleAllExceptions(ex: Exception, request: WebRequest): ResponseEntity<String> {
return ResponseEntity("Internal Server Error: ${ex.message}", HttpStatus.INTERNAL_SERVER_ERROR)
}

@ExceptionHandler(ResourceNotFoundException::class)
fun handleResourceNotFoundException(ex: ResourceNotFoundException, request: WebRequest): ResponseEntity<String> {
return ResponseEntity("Resource Not Found: ${ex.message}", HttpStatus.NOT_FOUND)
}

@ExceptionHandler(BadRequestException::class)
fun handleBadRequestException(ex: BadRequestException, request: WebRequest): ResponseEntity<String> {
return ResponseEntity("Bad Request: ${ex.message}", HttpStatus.BAD_REQUEST)
}
}
@ControllerAdvice
class GlobalExceptionHandler {

@ExceptionHandler(Exception::class)
fun handleAllExceptions(ex: Exception, request: WebRequest): ResponseEntity<String> {
return ResponseEntity("Internal Server Error: ${ex.message}", HttpStatus.INTERNAL_SERVER_ERROR)
}

@ExceptionHandler(ResourceNotFoundException::class)
fun handleResourceNotFoundException(ex: ResourceNotFoundException, request: WebRequest): ResponseEntity<String> {
return ResponseEntity("Resource Not Found: ${ex.message}", HttpStatus.NOT_FOUND)
}

@ExceptionHandler(BadRequestException::class)
fun handleBadRequestException(ex: BadRequestException, request: WebRequest): ResponseEntity<String> {
return ResponseEntity("Bad Request: ${ex.message}", HttpStatus.BAD_REQUEST)
}
}
exception<Exception> {
response {
content = "An error occured! ${exception.message}"
}
}
exception<Exception> {
response {
content = "An error occured! ${exception.message}"
}
}
Something like that would be neat
gdude
gdude5mo ago
I don't really see any practical use for that given the current formatting features But also, sending your exception message or traceback is poor UX, which is why most big bots don't do it If you want to be notified of production errors and keep track of them, use the Sentry integration
Shaun
ShaunOP5mo ago
Ok
gdude
gdude5mo ago
Sentry provides a free plan for small projects, OSS project sponsorships, and you can also self host it It's an excellent service
Shaun
ShaunOP5mo ago
Which event is fired when the bot is added to a guild So I can send a welcome message
gdude
gdude5mo ago
Guild create I think? But it's also fired on startup You'll need to store some state so you know whether you've sent the welcome message before Though on some servers, you won't have a channel to send one to, so bear that in mind Was your original question solved? We shouldn't reuse the same thread for a different question
Shaun
ShaunOP5mo ago
Yes
gdude
gdude5mo ago
can you mark the solution then?
gdude
gdude5mo ago
No description
gdude
gdude5mo ago
thank
Want results from more Discord servers?
Add your server