Code Monkey home page Code Monkey logo

Comments (4)

zekroTJA avatar zekroTJA commented on July 4, 2024

Can you show me how I can reproduce the issue?

from ken.

Astridalia avatar Astridalia commented on July 4, 2024

Sure, here's some code:

func (*ImageboardCommand) Run(ctx ken.Context) (err error) {
	if err = ctx.Defer(); err != nil {
		return
	}
	bd := AssertArgument(ctx)
	message := ctx.FollowUpEmbed(bd.Modal())
	message.AddComponents(func(cb *ken.ComponentBuilder) {
		cb.AddActionsRow(func(b ken.ComponentAssembler) {
			b.Add(discordgo.Button{
				CustomID: fmt.Sprint(rand.Intn(3000)),
				Style:    discordgo.PrimaryButton,
				Label:    "⏭️",
			}, func(ctx ken.ComponentContext) bool {
				bd.Next()
				message.Send().EditEmbed(bd.Modal())
				return true
			})
		})
	})
	message.Send()
	return err
}

from ken.

zekroTJA avatar zekroTJA commented on July 4, 2024

Yeah, there are definitely some Issues with your code.

First of all, ctx.FollowUpEmbed does now return a *FollowUpMessageBuilder which can be turned into a *FollowUpMessage by using the Send method on it.

So, the second call to Send in your component handler does not make a lot of sense, because the message has already been sent. You need to capture the resulting *FollowUpMessage and perform EditEmbed on that.

Something like this should work.

func (*ImageboardCommand) Run(ctx ken.Context) (err error) {
	if err = ctx.Defer(); err != nil {
		return
	}

        var fum *ken.FollowUpMessage

	bd := AssertArgument(ctx)
	message := ctx.FollowUpEmbed(bd.Modal())
	message.AddComponents(func(cb *ken.ComponentBuilder) {
		cb.AddActionsRow(func(b ken.ComponentAssembler) {
			b.Add(discordgo.Button{
				CustomID: fmt.Sprint(rand.Intn(3000)),
				Style:    discordgo.PrimaryButton,
				Label:    "⏭️",
			}, func(ctx ken.ComponentContext) bool {
				bd.Next()
				fum.EditEmbed(bd.Modal())
				return true
			})
		})
	})

	fum = message.Send()

	return fum.Error
}

Also, because Send does not directly return an error, the errors in the call chain are captured in the FollowUpMessage's property Error, which should be checked after performing actions like Send or EditEmbed. I know that this approach is not very easy to see through but I am working on it to make the API more understandable and usable. 😄

from ken.

Astridalia avatar Astridalia commented on July 4, 2024

Ah, alright thanks for the advice!

from ken.

Related Issues (12)

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.