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

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

  2. <tfoot id='eQGmy'></tfoot>
      <bdo id='eQGmy'></bdo><ul id='eQGmy'></ul>

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

      如何僅在觸發當前命令時使用命令?

      How to use commands only when a current command is triggered?(如何僅在觸發當前命令時使用命令?)

            <tbody id='XS0sm'></tbody>
              <bdo id='XS0sm'></bdo><ul id='XS0sm'></ul>

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

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

              • <legend id='XS0sm'><style id='XS0sm'><dir id='XS0sm'><q id='XS0sm'></q></dir></style></legend>
                本文介紹了如何僅在觸發當前命令時使用命令?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                這個問題可能很復雜,我的大腦無法很好地解釋它,所以請用這個蹩腳的解釋來解釋,我的問題,當你觸發一個命令時,例如 .start 它將開始讓我們說一個基于文本的游戲,當然您將擁有能夠實際玩游戲的命令,但我擔心人們仍然可以觸發游戲內命令而無需啟動游戲.

                This question might be complicated and my brain can't really explain it well so please bare with this crappy explanation, My question, When you trigger a command for example .start it will start let's say a text based game, of course you would have the commands to be able to actually play the game however my concern is people can still trigger the ingame commands without needing to start the game for example .

                     if message.content.startswith("/play"):       #Here is the play command where you execute the game to start
                         await client.send_message(message.channel, "Welcome to the game!")
                     if message.content.startswith("/examine):
                         await client.send_message(message.channel, "You examined the rock and well, got a rock!") #In-Game commands/movements
                

                我的意思是,有沒有辦法只有在游戲本身被激活時才能使用游戲中的命令?附加問題:您將如何存儲用戶的信息,例如基本上保存游戲(您實際上不需要回答這個問題,因為我想自己學習,但任何提示都會很棒!)

                What i'm saying is, is there a way of only being able to use the in-game commands only when the game itself is activated? Additional Question: How would you store a user's information like basically saving the game (You don't really need to answer this as i would like to learn this myself but any tips would be great!)

                推薦答案

                首先,我們需要一些對象來存儲特定會話的狀態.我們可以把這個對象稱為Game.我們將維護 discord.Users 到 Games 的映射.此映射中存在的 User 表示他們正在玩游戲.一些基礎知識類似于:

                First, we want some object that stores the state of a particular session. We can just call this object Game. We'll maintain a mapping of discord.Users to Games. A User existing in this mapping means that they are playing the game. Some basics would look something like:

                from discord.ext import commands
                
                class Game:
                    def __init__(self):
                        self.points = 0
                        self.inventory = []
                
                bot = commands.Bot('/')
                
                sessions = {}
                
                @bot.command(pass_context=True)
                async def play(ctx):
                    if ctx.message.author.id in sessions:
                        await bot.say("You're already playing")
                        return
                    sessions[ctx.message.author.id] = Game()
                    await bot.say("Welcome to the game!")
                
                @bot.command(pass_context=True)
                async def quit(ctx):
                    if ctx.message.author.id not in sessions:
                        await bot.say("You're not playing the game")
                        return
                    del sessions[ctx.message.author.id]
                    await bot.say("Game Over")
                
                @bot.command(pass_context=True)
                async def examine(ctx):
                    session = sessions.get(ctx.message.author.id, None)
                    if session is None:
                        await bot.say("You're not playing the game")
                        return
                    session.inventory.append("A rock")
                    await bot.say("You examined the rock and well, got a rock!")
                
                bot.run("TOKEN")
                

                您可以做一些事情來擴展它:利用 checks 和 CommandErrors 來避免重復檢查會話的代碼;確保 Game 是 pickleable,并編寫使用pickle保存游戲的代碼;寫一個比收集石頭更有趣的游戲.

                Some things you could do to extend this: make use of checks and CommandErrors to avoid having to repeat the code for checking sessions; make sure that Games are pickleable, and write code for saving games using pickle; write a game that's more fun than collecting rocks.

                這篇關于如何僅在觸發當前命令時使用命令?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 自動更改角色顏色)
                    <tfoot id='VKOQp'></tfoot>
                      <tbody id='VKOQp'></tbody>

                        <legend id='VKOQp'><style id='VKOQp'><dir id='VKOQp'><q id='VKOQp'></q></dir></style></legend>

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

                      • <i id='VKOQp'><tr id='VKOQp'><dt id='VKOQp'><q id='VKOQp'><span id='VKOQp'><b id='VKOQp'><form id='VKOQp'><ins id='VKOQp'></ins><ul id='VKOQp'></ul><sub id='VKOQp'></sub></form><legend id='VKOQp'></legend><bdo id='VKOQp'><pre id='VKOQp'><center id='VKOQp'></center></pre></bdo></b><th id='VKOQp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VKOQp'><tfoot id='VKOQp'></tfoot><dl id='VKOQp'><fieldset id='VKOQp'></fieldset></dl></div>
                          <bdo id='VKOQp'></bdo><ul id='VKOQp'></ul>
                        • 主站蜘蛛池模板: 亚洲精品久久久久久一区二区 | 精品国产一区二区三区久久久蜜月 | 日一区二区 | 欧美人人 | 激情在线视频网站 | 国产高清毛片 | av色噜噜| 色婷婷综合久久久中字幕精品久久 | 亚洲国产精品一区二区久久 | 男女下面一进一出网站 | caoporn国产精品免费公开 | 久久久久久久久久久久久91 | 国产精品国色综合久久 | 成人国产精品入口免费视频 | 欧美一级网站 | 亚洲午夜视频 | 亚洲欧美激情网 | 亚洲激情在线视频 | 国产小网站| 国产精品国产三级国产aⅴ中文 | 久久久精品一区二区三区四季av | 中文字幕视频在线 | 黄色免费网址大全 | 国产精品免费一区二区三区四区 | 91久操视频 | 精品免费国产一区二区三区 | 色www精品视频在线观看 | 欧美视频1区 | 日韩在线视频免费观看 | 亚洲精品自在在线观看 | 亚洲一区二区网站 | 日本精品视频一区二区三区四区 | 国产激情精品一区二区三区 | 成人免费在线观看视频 | 免费观看一区二区三区毛片 | 亚洲一区自拍 | 国产一级片 | h片在线看 | 综合久久久久久久 | av无遮挡 | 黄色片在线网站 |