pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    • <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="xlprlxb" 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="hlj7zh7" 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="hxl7ptx" 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>
                          主站蜘蛛池模板: 底部填充胶_电子封装胶_芯片封装胶_芯片底部填充胶厂家-东莞汉思新材料 | 山东聚盛新型材料有限公司-纳米防腐隔热彩铝板和纳米防腐隔热板以及钛锡板、PVDF氟膜板供应商 | 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 | 2025世界机器人大会_IC China_半导体展_集成电路博览会_智能制造展览网 | 龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司_龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司 | 超声波清洗机_大型超声波清洗机_工业超声波清洗设备-洁盟清洗设备 | 悬浮拼装地板_篮球场木地板翻新_运动木地板价格-上海越禾运动地板厂家 | 冷却塔降噪隔音_冷却塔噪声治理_冷却塔噪音处理厂家-广东康明冷却塔降噪厂家 | 云南标线|昆明划线|道路标线|交通标线-就选云南云路施工公司-云南云路科技有限公司 | 酵素生产厂家_酵素OEM_酵素加盟_酵素ODM_酵素原料厂家_厦门益力康 | 空调风机,低噪声离心式通风机,不锈钢防爆风机,前倾皮带传动风机,后倾空调风机-山东捷风风机有限公司 | 广东燎了网络科技有限公司官网-网站建设-珠海网络推广-高端营销型外贸网站建设-珠海专业h5建站公司「了了网」 | 碳纤维布-植筋胶-灌缝胶-固特嘉加固材料公司 | 学习安徽网| 七维官网-水性工业漆_轨道交通涂料_钢结构漆 | 昆明化妆培训-纹绣美甲-美容美牙培训-昆明博澜培训学校 | 一路商机网-品牌招商加盟优选平台-加盟店排行榜平台 | 渣油泵,KCB齿轮泵,不锈钢齿轮泵,重油泵,煤焦油泵,泊头市泰邦泵阀制造有限公司 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 丹佛斯变频器-Danfoss战略代理经销商-上海津信变频器有限公司 | 视觉检测设备_自动化检测设备_CCD视觉检测机_外观缺陷检测-瑞智光电 | YJLV22铝芯铠装电缆-MYPTJ矿用高压橡套电缆-天津市电缆总厂 | 警方提醒:赣州约炮论坛真的安全吗?2025年新手必看的网络交友防坑指南 | 河南彩印编织袋,郑州饲料编织袋定制,肥料编织袋加工厂-盛军塑业 河南凯邦机械制造有限公司 | 运动木地板_体育木地板_篮球馆木地板_舞台木地板-实木运动地板厂家 | 硫酸钡厂家_高光沉淀硫酸钡价格-河南钡丰化工有限公司 | 光纤测温-荧光光纤测温系统-福州华光天锐光电科技有限公司 | 361°官方网站 | 珠海网站建设_响应网站建设_珠海建站公司_珠海网站设计与制作_珠海网讯互联 | 石家庄律师_石家庄刑事辩护律师_石家庄取保候审-河北万垚律师事务所 | 东莞市踏板石餐饮管理有限公司_正宗桂林米粉_正宗桂林米粉加盟_桂林米粉加盟费-东莞市棒子桂林米粉 | 食安观察网 | 钛板_钛管_钛棒_钛盘管-无锡市盛钛科技有限公司 | 带式过滤机厂家_价格_型号规格参数-江西核威环保科技有限公司 | 国产频谱分析仪-国产网络分析仪-上海坚融实业有限公司 | 上海质量认证办理中心| 抖音短视频运营_企业网站建设_网络推广_全网自媒体营销-东莞市凌天信息科技有限公司 | 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 钢制拖链生产厂家-全封闭钢制拖链-能源钢铝拖链-工程塑料拖链-河北汉洋机械制造有限公司 | 超高频感应加热设备_高频感应电源厂家_CCD视觉检测设备_振动盘视觉检测设备_深圳雨滴科技-深圳市雨滴科技有限公司 | 杭州画室_十大画室_白墙画室_杭州美术培训_国美附中培训_附中考前培训_升学率高的画室_美术中考集训美术高考集训基地 |