在這里,當玩家輸入 '!start' 時,他將被添加到記分板字典中。
if message.content.startswith('!start'):
await message.channel.send("The game starts")
self.scoreboard = {}
***在這里,一旦他輸入“!play”,機器人就會給出所有玩家的串列( message.author.name ),并將他的分數設為 0 以 0 分開始測驗***
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
在機器人提出問題并且玩家正確回答之后,我希望正確的玩家獲得 1 分。如何將字典中的值 1 添加到正確的播放器?
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')
uj5u.com熱心網友回復:
您可以檢查訊息的作者是否在記分板字典中,然后使用 Python 中的加法運算子增加分數計數。
if message.author.name in self.scoreboard:
self.scoreboard[message.author.name] = 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/395688.html
