<bdo id='y5noD'></bdo><ul id='y5noD'></ul>

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

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

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

      <i id='y5noD'><tr id='y5noD'><dt id='y5noD'><q id='y5noD'><span id='y5noD'><b id='y5noD'><form id='y5noD'><ins id='y5noD'></ins><ul id='y5noD'></ul><sub id='y5noD'></sub></form><legend id='y5noD'></legend><bdo id='y5noD'><pre id='y5noD'><center id='y5noD'></center></pre></bdo></b><th id='y5noD'></th></span></q></dt></tr></i><div id='y5noD'><tfoot id='y5noD'></tfoot><dl id='y5noD'><fieldset id='y5noD'></fieldset></dl></div>
    2. 每个服务器前缀

      时间:2023-09-09

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

        1. <small id='nX3O9'></small><noframes id='nX3O9'>

          <i id='nX3O9'><tr id='nX3O9'><dt id='nX3O9'><q id='nX3O9'><span id='nX3O9'><b id='nX3O9'><form id='nX3O9'><ins id='nX3O9'></ins><ul id='nX3O9'></ul><sub id='nX3O9'></sub></form><legend id='nX3O9'></legend><bdo id='nX3O9'><pre id='nX3O9'><center id='nX3O9'></center></pre></bdo></b><th id='nX3O9'></th></span></q></dt></tr></i><div id='nX3O9'><tfoot id='nX3O9'></tfoot><dl id='nX3O9'><fieldset id='nX3O9'></fieldset></dl></div>
              <tfoot id='nX3O9'></tfoot>
                <tbody id='nX3O9'></tbody>
                <legend id='nX3O9'><style id='nX3O9'><dir id='nX3O9'><q id='nX3O9'></q></dir></style></legend>
                本文介绍了每个服务器前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我想知道如何让我的机器人连接到的每台服务器都设置自己的前缀.我正在使用带有 Commands ext 的异步版本的 dpy.我假设您会将前缀和服务器名称存储在 .json 文件中,但我不知道您将如何编写它们或检查文件.

                I was wondering how I would go about allowing every server my bot is connected to, to set their own prefix. I am using the async version of dpy with Commands ext. I would assume you would store the prefix's and server name in a .json file, but I don't know how you would write them or check the file for them.

                谢谢

                推荐答案

                您可以使用动态命令前缀来做到这一点.编写一个函数或协程,它接受一个 Bot 和一个 Message 并为该消息输出适当的前缀.假设您有一个服务器 ID 的 JSON 前缀:

                You can do this with dynamic command prefixes. Write a function or coroutine that takes a Bot and a Message and outputs the appropriate prefix for that message. Assuming you had a JSON of server ids to prefixes:

                { 
                  "1234": "!",
                  "5678": "?"
                }
                

                您可以将该 json 加载到字典中,然后在该字典中查找服务器 ID.下面我还包括一个默认前缀,但您也可以为没有特定前缀的服务器引发 CommandError 或其他内容.

                You can load that json into a dictionary and then look up server ids in that dictionary. Below I also include a default prefix, but you could also raise a CommandError or something for servers with no specific prefix.

                from discord import commands
                import json
                
                with open("prefixes.json") as f:
                    prefixes = json.load(f)
                default_prefix = "!"
                
                def prefix(bot, message):
                    id = message.guild.id
                    return prefixes.get(id, default_prefix)
                
                bot = commands.Bot(command_prefix=prefix)
                
                ...
                

                这篇关于每个服务器前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:@client.event 到底是什么?不和谐.py 下一篇:Discord.py Bot 的权限系统

                相关文章

                最新文章

                1. <small id='k8wCK'></small><noframes id='k8wCK'>

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