DEV Community

Cover image for Making of Among Us in Discord - DEVBLOG 4 - Start Screen...(1/3)
Mr.StiK
Mr.StiK

Posted on

Making of Among Us in Discord - DEVBLOG 4 - Start Screen...(1/3)

Heya, this is~ you know who am I, don't you!

So, quick coding, I made the Start Screen today most of it, because I'm fasting, and exams too so I might get only little time to code, so... Time is Precious!

I think my blogs are not having coding content, so, I might share code next blogs... but here's today's code for a good start.

players = []
host = ''
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):
            players.append(f'{interaction.user.name}#{interaction.user.discriminator}')
            await interaction.response.send_message("You've successfully joined the GAME!!!", ephemeral=True)
            print(players)
            self.value = False
            self.stop()

@bot.command()
async def start(ctx):
    start_embed = discord.Embed(
        colour=discord.Colour.red(),
        title='Welcome to the **LOBBY**',
        description='Game will start once there are enough players and to join, Click "Join Game"'

    )

    start_view = StartButton()
    await ctx.send(embed=start_embed, view=start_view)

Enter fullscreen mode Exit fullscreen mode

So, yeah, let me explain a bit:

players is a list (or an array, in other language terms :) ) and host is a string and these variables will contain user names... and I think you may know what are their uses... -_-

And when somebody starts a game, the user who said that will be the host (it is not included, maybe tomorrow) ( [❕] StiK will remember that...) and the users who press Join gets their name in the players list and actually adds their username by getting the name and discriminator value. The username string goes:

f'{interaction.user.name}#{interaction.user.discriminator}'

I made it a formative string for doing it easy, example, just say UserGuy#0001 clicked this. That guy is the interaction.user, his name being 'UserGuy' and discriminator '0001'. So, I first formatted the name variable then a '#' goes on and then finally the discriminator. Thus we got the name!

My plan is to add these players in a 'Nested Dictionary' with their color and role as a dictionary... so it might be easy to manage them and their actions and roles...

So, yeah, if you have suggestions, please, PLEASE let me know because as you can see, I'm new to python and I'll never forget the help.

[PS: GOTO THE OG TWEET AND YOU'LL SEE THE SECOND IMAGE I WAS TALKING ABOUT IN THE TWEET]

So, yeah, that's for today,

Toodles.

Top comments (0)