久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='ARkD2'></bdo><ul id='ARkD2'></ul>

    <legend id='ARkD2'><style id='ARkD2'><dir id='ARkD2'><q id='ARkD2'></q></dir></style></legend>
    <i id='ARkD2'><tr id='ARkD2'><dt id='ARkD2'><q id='ARkD2'><span id='ARkD2'><b id='ARkD2'><form id='ARkD2'><ins id='ARkD2'></ins><ul id='ARkD2'></ul><sub id='ARkD2'></sub></form><legend id='ARkD2'></legend><bdo id='ARkD2'><pre id='ARkD2'><center id='ARkD2'></center></pre></bdo></b><th id='ARkD2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ARkD2'><tfoot id='ARkD2'></tfoot><dl id='ARkD2'><fieldset id='ARkD2'></fieldset></dl></div>

      <small id='ARkD2'></small><noframes id='ARkD2'>

    1. <tfoot id='ARkD2'></tfoot>

      體驗 (XP) 不適用于所有用戶 JSON Discord.PY

      Experience (XP) not working for all users JSON Discord.PY(體驗 (XP) 不適用于所有用戶 JSON Discord.PY)
          <tbody id='gbsEA'></tbody>

        <i id='gbsEA'><tr id='gbsEA'><dt id='gbsEA'><q id='gbsEA'><span id='gbsEA'><b id='gbsEA'><form id='gbsEA'><ins id='gbsEA'></ins><ul id='gbsEA'></ul><sub id='gbsEA'></sub></form><legend id='gbsEA'></legend><bdo id='gbsEA'><pre id='gbsEA'><center id='gbsEA'></center></pre></bdo></b><th id='gbsEA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gbsEA'><tfoot id='gbsEA'></tfoot><dl id='gbsEA'><fieldset id='gbsEA'></fieldset></dl></div>

      • <tfoot id='gbsEA'></tfoot>
                <bdo id='gbsEA'></bdo><ul id='gbsEA'></ul>

                <legend id='gbsEA'><style id='gbsEA'><dir id='gbsEA'><q id='gbsEA'></q></dir></style></legend>
              • <small id='gbsEA'></small><noframes id='gbsEA'>

              • 本文介紹了體驗 (XP) 不適用于所有用戶 JSON Discord.PY的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試為在大約有 50-60 人輸入的房間中輸入的消息打分.它將第一次將用戶添加到 JSON 文件中,但不會為他們鍵入的消息添加任何分數.我再次對其進行了測試,只有一個用戶獲得了他們輸入的消息的積分,其余的保持不變.代碼如下:

                I'm trying to give points for messages typed in a room that has around 50-60 people that type in it. It will add the user to the JSON file the first time, but it won't add any more points for the messages they type. I tested it again and only one user was getting points for the messages they typed and the rest remained the same. Here is the code:

                 @client.event
                async def on_message(message):
                
                    if message.content.lower().startswith('!points'):
                        await client.send_message(message.channel, "You have {} points!".format(get_points(message.author.id)))
                
                    user_add_points(message.author.id,1)
                
                def user_add_points(user_id: int, points: int):
                    if os.path.isfile("users.json"):
                        try: 
                            with open('users.json', 'r') as fp:
                                users = json.load(fp)
                            users[user_id]['points'] += points
                            with open('users.json', 'w') as fp:
                                json.dump(users, fp, sort_keys=True, indent=4)
                        except KeyError:
                            with open('users.json', 'r') as fp:
                                users = json.load(fp)
                            users[user_id] = {}
                            users[user_id]['points'] = points
                            with open('users.json', 'w') as fp:
                                json.dump(users, fp, sort_keys=True, indent = 4)
                    else:
                        users = {user_id:{}}
                        users[user_id]['points'] = points
                        with open('users.json', 'w') as fp:
                            json.dump(users, fp, sort_keys=True, indent=4)
                
                def get_points(user_id: int):
                    if os.path.isfile('users.json'):
                        with open('users.json', 'r') as fp:
                            users = json.load(fp)
                        return users[user_id]['points']
                    else:
                        return 0
                

                推薦答案

                我們應該只需要讀取一次文件,然后在需要時將修改保存到文件中.我沒有注意到任何會導致所描述行為的邏輯錯誤,因此這可能是關于允許您的機器人查看哪些消息的權限問題.為了便于調試,我簡化了您的代碼并添加了一些打印來跟蹤正在發生的事情.我還在 on_message 中添加了一個守衛,以阻止機器人對其自身做出響應.

                We should only need to read the file once, and then just save our modifications to the file when we need to. I didn't notice any logical errors that would lead to the behavior described, so it may be a permissions issue regarding what messages your bot is allowed to see. To facilitate debugging, I've simplified your code and added some prints to track what's going on. I also added a guard in on_message to stop the bot from responding to itself.

                import json
                import discord
                
                client = discord.Client()
                
                try:
                    with open("users.json") as fp:
                        users = json.load(fp)
                except Exception:
                    users = {}
                
                def save_users():
                    with open("users.json", "w+") as fp:
                        json.dump(users, fp, sort_keys=True, indent=4)
                
                def add_points(user: discord.User, points: int):
                    id = user.id
                    if id not in users:
                        users[id] = {}
                    users[id]["points"] = users[id].get("points", 0) + points
                    print("{} now has {} points".format(user.name, users[id]["points"]))
                    save_users()
                
                def get_points(user: discord.User):
                    id = user.id
                    if id in users:
                        return users[id].get("points", 0)
                    return 0
                
                @client.event
                async def on_message(message):
                    if message.author == client.user:
                        return
                    print("{} sent a message".format(message.author.name))
                    if message.content.lower().startswith("!points"):
                        msg = "You have {} points!".format(get_points(message.author))
                        await client.send_message(message.channel, msg)
                    add_points(message.author, 1)
                
                client.run("token")
                

                這篇關于體驗 (XP) 不適用于所有用戶 JSON Discord.PY的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                  <bdo id='uQJ2c'></bdo><ul id='uQJ2c'></ul>

                    • <small id='uQJ2c'></small><noframes id='uQJ2c'>

                    • <i id='uQJ2c'><tr id='uQJ2c'><dt id='uQJ2c'><q id='uQJ2c'><span id='uQJ2c'><b id='uQJ2c'><form id='uQJ2c'><ins id='uQJ2c'></ins><ul id='uQJ2c'></ul><sub id='uQJ2c'></sub></form><legend id='uQJ2c'></legend><bdo id='uQJ2c'><pre id='uQJ2c'><center id='uQJ2c'></center></pre></bdo></b><th id='uQJ2c'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uQJ2c'><tfoot id='uQJ2c'></tfoot><dl id='uQJ2c'><fieldset id='uQJ2c'></fieldset></dl></div>
                        <tbody id='uQJ2c'></tbody>

                      1. <tfoot id='uQJ2c'></tfoot>

                          <legend id='uQJ2c'><style id='uQJ2c'><dir id='uQJ2c'><q id='uQJ2c'></q></dir></style></legend>
                          主站蜘蛛池模板: 亚洲精品欧美 | 欧美精品在线免费 | 黄网站色大毛片 | 97久久久| 国产精品18毛片一区二区 | 精品在线观看入口 | 欧美一区二区在线观看 | 天天射视频 | 久久er精品 | 亚洲午夜精品一区二区三区 | 中文字幕国产精品 | 中文字幕一区二区三区四区五区 | 华丽的挑战在线观看 | 亚洲一区在线观看视频 | 亚洲欧美一区二区三区国产精品 | 国产精品视频一区二区三区 | 日本精品一区二区三区视频 | 男女羞羞视频在线观看 | 一区二区三区视频在线观看 | 久久久久久久久久久久久9999 | 北条麻妃av一区二区三区 | 亚洲午夜精品视频 | 精品久久国产视频 | 国产精品一二三区在线观看 | 午夜免费| 欧美视频成人 | 午夜精品三区 | 天堂一区 | 亚洲精品久久久久久一区二区 | 久久大 | 欧洲亚洲精品久久久久 | 欧日韩在线观看 | 精品国产18久久久久久二百 | 伊人网在线播放 | 成人免费片 | 欧美午夜精品理论片a级按摩 | 久久lu | 亚洲欧洲在线视频 | 热99精品视频 | 久草高清视频 | 视频精品一区二区三区 |