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

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

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

    1. <legend id='TAzWu'><style id='TAzWu'><dir id='TAzWu'><q id='TAzWu'></q></dir></style></legend>
    2. 將冷卻時間/計時器添加到 on_message [Discord.py]

      Add cooldown / timer to on_message [Discord.py](將冷卻時間/計時器添加到 on_message [Discord.py])
      <i id='rwTpF'><tr id='rwTpF'><dt id='rwTpF'><q id='rwTpF'><span id='rwTpF'><b id='rwTpF'><form id='rwTpF'><ins id='rwTpF'></ins><ul id='rwTpF'></ul><sub id='rwTpF'></sub></form><legend id='rwTpF'></legend><bdo id='rwTpF'><pre id='rwTpF'><center id='rwTpF'></center></pre></bdo></b><th id='rwTpF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rwTpF'><tfoot id='rwTpF'></tfoot><dl id='rwTpF'><fieldset id='rwTpF'></fieldset></dl></div>

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

          <tbody id='rwTpF'></tbody>

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

      • <legend id='rwTpF'><style id='rwTpF'><dir id='rwTpF'><q id='rwTpF'></q></dir></style></legend>

              • 本文介紹了將冷卻時間/計時器添加到 on_message [Discord.py]的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我最近開始用 Python 制作一個 Discord 機器人(用它測試 Python 的基礎),并自己創建了一個帶有多個命令的功能性機器人.為了擴大它的用途,我添加了一個級別/XP 系統,該系統目前正在運行.

                I got into making a Discord bot in Python very recently (testing the grounds of Python with it) and created a functioning one with several commands myself. To widen its uses, I have added a level/XP system, which is working so far.

                [...]
                @bot.event
                async def on_message(message):
                        user_add_xp(message.author.id, 2)
                        await bot.process_commands(message)
                
                # commands go here
                
                def user_add_xp(user_id, xp):
                    if os.path.isfile('users.json'):
                            try:
                                    with open('users.json', 'r') as fp:
                                            users = json.load(fp)
                                    users[user_id]['xp'] += xp
                                    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]['xp'] = xp
                                    with open('users.json', 'w') as fp:
                                            json.dump(users, fp, sort_keys=True, indent=4)
                    else:
                        users = {user_id: {}}
                        users[user_id]['xp'] = xp
                        with open('users.json', 'w') as fp:
                                json.dump(users, fp, sort_keys=True, indent=4)
                [...]
                

                但為了防止用戶只是泛濫/垃圾郵件某些頻道并飆升至頂部,我想為 XP 獎勵添加一個冷卻時間/計時器.我嘗試將 @commands.cooldown(1, 120, commands.BucketType.server) 添加到 @bot.eventuser_add_xp,但兩者都沒有得到我想要的結果.我不知道如何添加此冷卻時間/計時器.

                But to prevent users from just flooding/spamming some channels and rocketing to the top, I want to add a cooldown/timer on the awarding of XP. I have tried to add @commands.cooldown(1, 120, commands.BucketType.server) to both @bot.event and user_add_xp, but both do not get me the desired result. I have no other idea how to add this cooldown/timer.

                最后,我希望機器人每兩分鐘只授予一次 XP.

                In the end, I want the bot to only grant XP once every two minutes.

                推薦答案

                不確定是否可以僅使用 discord.py,但您可以存儲最后一次將消息授予用戶 XP 的時間在你的字典里.

                Not sure if it's possible with just discord.py, but you can store the last time a message was awarded XP to a user in your dictionary.

                以下代碼存儲自靜態開始日期(epoch)消息獎勵 XP 以來的秒數.然后,它會檢查發生新消息事件的時間.

                The below code stores the number of seconds since a static start date (epoch) when a message awards XP. It then checks against this time when a new message event happens.

                [...]
                import datetime
                
                epoch = datetime.datetime.utcfromtimestamp(0)
                
                @bot.event
                async def on_message(message):
                    user_add_xp(message.author.id, 2)
                    await bot.process_commands(message)
                
                # commands go here
                
                def user_add_xp(user_id, xp):
                    if os.path.isfile('users.json'):
                        try:
                            with open('users.json', 'r') as fp:
                                users = json.load(fp)
                
                            time_diff = (datetime.datetime.utcnow() - epoch).total_seconds() - users[user_id]['xp_time']
                            if time_diff >= 120:
                                users[user_id]['xp'] += xp
                                users[user_id]['xp_time'] = (datetime.datetime.utcnow() - epoch).total_seconds()
                                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]['xp'] = xp
                            users[user_id]['xp_time'] = (datetime.datetime.utcnow() - epoch).total_seconds()
                            with open('users.json', 'w') as fp:
                                json.dump(users, fp, sort_keys=True, indent=4)
                    else:
                        users = {user_id: {}}
                        users[user_id]['xp'] = xp
                        users[user_id]['xp_time'] = (datetime.datetime.utcnow() - epoch).total_seconds()
                        with open('users.json', 'w') as fp:
                            json.dump(users, fp, sort_keys=True, indent=4)
                [...]
                

                這篇關于將冷卻時間/計時器添加到 on_message [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 - 自動更改角色顏色)
                    <tbody id='jTxR8'></tbody>
                • <legend id='jTxR8'><style id='jTxR8'><dir id='jTxR8'><q id='jTxR8'></q></dir></style></legend>

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

                        <tfoot id='jTxR8'></tfoot>

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

                          主站蜘蛛池模板: 婷婷精品 | 精品视频国产 | 国产精品自产拍 | 欧美一区二区三区在线看 | 久草视| 女人牲交视频一级毛片 | 黄视频国产| 亚洲在线免费 | 一区二区三区四区不卡视频 | www.久久久.com | 久久久激情视频 | 在线精品一区二区三区 | 久久99精品久久久久久国产越南 | 久久精品二区 | 久综合| 国产1区| 国产欧美精品在线观看 | 99精品欧美一区二区蜜桃免费 | 欧美激情一区二区三区 | 国产精品久久久久久中文字 | 欧美性久久 | 狠狠涩 | 99爱视频| 嫩草视频在线免费观看 | 欧美日韩第一页 | 亚洲久视频 | 久久精品99 | 成人黄色电影免费 | 狠狠撸在线视频 | 91麻豆产精品久久久久久夏晴子 | 国产二区av| 日韩久久综合网 | 精品一区二区三区电影 | 美女黄网| 在线看国产 | 欧洲成人免费视频 | 99久久精品国产一区二区三区 | 国产精品区一区二区三 | 精品亚洲一区二区三区四区五区 | 国产成人精品久久二区二区 | 精品视频99 |