DEV Community

Cover image for Making of Among Us in Discord - DEVBLOG 6 - Start Screen DONE...kinda? (3/3)
Mr.StiK
Mr.StiK

Posted on • Edited on

2

Making of Among Us in Discord - DEVBLOG 6 - Start Screen DONE...kinda? (3/3)

Heya, this is Mr.StiK.
[Mr.StiK's intro Dialogue counter: 7]

So, just like the tweet above and the counter joke just above (XD), I made a counter system in the bot.

Basically I don't have hopes of editing that dang embed message... so, I found a perfect solution...

Yes, you may can understand I'm in a grave situation of coding till 1:20 AM, and I'm fed of it.

discord.py server was... unaware... of my 'problem', so I need to find my own solution... and I did it, I coded it all by myself~

No, seriously, thanks to CHATGPT for fixing my error in the code.

And it's not in the tweet, but I just added players list on the message too (actually while typing... seriously). Here's the image of it:
Image description
Now, it's code time! Here's the promised code:

player_count = None
# Now actual stuff...
class StartButton(discord.ui.View):
    def __init__(self):
        super().__init__()
        self.value = None

    @discord.ui.button(label='Join Game', style=discord.ButtonStyle.grey)
    async def start_button(self, interaction: discord.Interaction, button: discord.ui.Button):
        if interaction.user.name in players:
            await interaction.response.send_message('You already joined the game', ephemeral=True)
        else:
            players.append(interaction.user.name)
            await interaction.response.send_message("You've successfully joined the GAME!!!", ephemeral=True)
        print(players)
        await player_count.edit(content="Total count of players is `"+ str(len(players)) + '` And Players are: `' + str(players) + '`')
        self.value = True

@bot.command()
async def start(ctx):
    global player_count
    players.clear()
    lobby_admin = ctx.author.name
    players.append(ctx.author.name)
    start_view = StartButton()
    print(players)
    await ctx.send(embed=start_embed, view=start_view)
    player_count = await ctx.send("Total count of players is `"+ str(len(players)) + '` And Players are: `' + str(players) + '`')


Enter fullscreen mode Exit fullscreen mode

As you can see, player_count (which is the message of player counting because for editing message purpose) is assigned as None. This is because if we're assigning it on start command (async def start()) we can't use it for editing while interaction, who's code is on top. So, I already assigned a variable like that BEFORE that. And that solution worked...

Unfortunately, I can't see the change CHATGPT made, because... I don't know where it is. It looks like the same code!

And the player counting thing took a bit of basic python knowledge (heh. 😏). For more on the rest of the code, see DEVBLOG 4.

So, yeah, that's it.

Toodles.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay