Jakes World
Jakes World

Reputation: 11

How should I store this and how do I do it? discord.py

I am struggling on something I am working on with my custom discord bot for someone. I have made a series of events that go like the picture here: Link to Example

I want to be able to store this in a JSON file or database without sending it straight away so later I can do things like:

I can not figure out how to store it in the Json file or database and be able to do those commands above. I have had little help from other devs but I still cant figure it out and need help on how to do it. Below is my code so far if someone can please help me:

    @bot.command()
    async def event(ctx):
        def check(msg):
            return msg.channel.id == ctx.channel.id and msg.author.id == ctx.author.id
        await ctx.send("Please enter the event name:")
        eventname = await bot.wait_for("message", check=check)
        await ctx.send("Please send what you want to say in the announcement in a code block:")
        codeblock = await bot.wait_for("message", check=check)
        await ctx.send("What image should be posted? (Type 'no' for none)")
        image = await bot.wait_for("message", check=check)
        mainimage = None
        if image.content.lower() != "no":
            mainimage = image.attachments[0]
        await ctx.send('What channel should the announcement be made in? (Please tag the channel)')
        eventch = await bot.wait_for("message", check=check)
        realchannel = await commands.TextChannelConverter().convert(ctx, eventch.content)
        message = codeblock.content.replace("```", "").replace("`", "")
        if mainimage:
            return await realchannel.send(message, file=await mainimage.to_file())
        await realchannel.send(message)

(Sorry if not indented properly, nor sure how to on here)

Help is appreciated.

Upvotes: 1

Views: 1053

Answers (1)

Manoj A
Manoj A

Reputation: 432

It kinda take too long to code so Im here to suggest a few steps to make it easy coding!

'

 dict = {}
 dict['name'] = ctx.message.content
 #same for all
  • after storing all kind of info in the dict. you can upload the dict to the database

  • Now the data are stored in Database! if you learned PyMongo you can easily do the rest of your queries!

Upvotes: 1

Related Questions