Giter VIP home page Giter VIP logo

Comments (6)

ms7m avatar ms7m commented on August 18, 2024 1

No problem!

There isn't a discord server yet. That sounds like a good idea for the future :)

from dispike.

ms7m avatar ms7m commented on August 18, 2024

You're on the right track.

There is an helper method available with the Dispike object called .background. Based on your steps, you could probably have something like this.

async def pong(ctx: IncomingDiscordInteraction):
    
    followup_message = FollowUpMessages(bot, interaction=ctx)
    await asyncio.sleep(2)

    response_followup = DiscordResponse(content="pong")
    await follow_up_message.async_create_follow_up_message(response_followup)


@bot.interaction.on("ping")
async def ping(ctx: IncomingDiscordInteraction) -> DiscordResponse:
    response = DiscordResponse(content="pong")


    # background 
    bot.background(pong, ctx)

    return response

I wouldn't use time for anything in an async function, but if you could probably use it if you replace async_create_follow_up_message with sync_create_follow_up_message.

I should write some documentation about this..

from dispike.

cgeopapa avatar cgeopapa commented on August 18, 2024

bot.background still requires to be awaited, and if I await it I just get the same result.

from dispike.

ms7m avatar ms7m commented on August 18, 2024

Ah, I see what you mean. I'll push an update to fix this behavior for .background..

from dispike.

ms7m avatar ms7m commented on August 18, 2024

Just pushed version 0.9.0a..

Testing with this example

async def later_pong(time_recieved, interaction: IncomingDiscordInteraction):
    now_time = datetime.datetime.now()
    time_diff = (now_time - time_recieved).total_seconds() * 1000

    _followup_object = FollowUpMessages(bot, interaction=interaction)
    await asyncio.sleep(10)

    pong_message  = DiscordResponse(show_user_input=False)
    pong_message.content = f"Pong: {time_diff}ms"
    await _followup_object.async_create_follow_up_message(pong_message)


@bot.interaction.on("ping")
async def ping(ctx: IncomingDiscordInteraction) -> DiscordResponse:
    await bot.background(later_pong, datetime.datetime.now(), ctx)

    logger.info("sending response ?")
    return DiscordResponse(
        content="Ping: ..."
    )

Let me know if you works out for you

from dispike.

cgeopapa avatar cgeopapa commented on August 18, 2024

There we go! Thank you!
Is there any discord server where I can join and get involved with this project? I see a lot of potential here.

from dispike.

Related Issues (20)

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.