Home > Mobile >  How can i add value ( 1 point ) to a specific player on my discord quiz game in python?
How can i add value ( 1 point ) to a specific player on my discord quiz game in python?

Time:12-28

Here when the player types '!start', he will be added to the scoreboard dictionary.

if message.content.startswith('!start'):
            await message.channel.send("The game starts")
            self.scoreboard = {}

***Here once he types '!play', the robot will give the list of all the players ( message.author.name ) and will put his score to 0 to start the quiz with 0 points ***

if message.content.startswith('!play'):
    txt = 'adding player: '   message.author.name
    await message.channel.send(txt)
    players.append(message.author.name)

    txt = 'current users: '   ' '.join(map(str, players))
    await message.channel.send(txt)
    self.scoreboard[message.author.name] = 0

After the robot gives the question and the player answers correctly, i would want the correct player to get 1 point. How can i add 1 to the value in the dictionary to the correct player?

    if message.content == '!score':
        score = str(self.scoreboard)
        print(score)
        await message.channel.send(self.scoreboard)
        return

    if message.content == self.answer:
        await message.channel.send('Good answer')

CodePudding user response:

You can check if the author of the message is in the scoreboard dictionary and then increment the score count using the addition operator in python.

if message.author.name in self.scoreboard:
    self.scoreboard[message.author.name]  = 1
  • Related