<small id='1OkJn'></small><noframes id='1OkJn'>

    <tfoot id='1OkJn'></tfoot><legend id='1OkJn'><style id='1OkJn'><dir id='1OkJn'><q id='1OkJn'></q></dir></style></legend>

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

      1. 使用 discord.py 获取频道名称

        时间:2023-09-09

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

              <tfoot id='aNl77'></tfoot>
                1. <small id='aNl77'></small><noframes id='aNl77'>

                    <tbody id='aNl77'></tbody>
                  本文介绍了使用 discord.py 获取频道名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何获取频道的名称,以便该机器人可以在其放置的任何服务器上运行,而无需更改代码?(在我放我在这里放什么"的代码中,我希望名称出现在变量中)谢谢

                  how do I get the name of a channel so that this bot will work on any server its put on with no changes to code necessary? ( in the code where I put "what do I put here" is where I want the name to be in a variable)Thanks

                  from discord.ext.commands import Bot
                  import time, asyncio
                  
                  TOKEN = 'Its a secret'
                  BOT_PREFIX = ["!"]
                  client = Bot(command_prefix=BOT_PREFIX)
                  
                  
                  
                  
                  @client.event
                  async def on_message(message):
                      if message.author == client.user:
                          return
                  
                  
                  
                  
                  @client.event
                  async def on_ready():
                      print('Logged in as')
                      print(client.user.name)
                      print(client.user.id)
                      print('------')
                      await start()
                      while True:
                          currentTime = time.strftime("%M%S", time.gmtime(time.time()))
                          if currentTime == "30:00":
                              await start()
                          await asyncio.sleep(1)
                  
                  
                  async def start():
                      mainChannel = #What do i put here?
                      print(mainChannel.name)
                      await client.send_message(mainChannel, "Starting countdown", tts = True)
                  
                  
                  
                  client.run(TOKEN)
                  

                  推荐答案

                  现在重写有一个方法叫做 discord.utils.get 您可以在其中实际获取具有特定参数的不和谐对象

                  Now in rewrite there's a method called discord.utils.get where you can actually getting discord objects with specific parameters

                  在您的情况下使用频道名称:

                  In your case with a channel name:

                  import discord
                  channel = discord.utils.get(guild.text_channels, name="Name of channel")
                  

                  如果 discord 找不到具有该名称的文本频道,则应为 None

                  Should be None if discord couldn't find a textchannel with that name

                  这篇关于使用 discord.py 获取频道名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Discord.py Bot 的权限系统 下一篇:如何使用 discord.py 获取不和谐用户的用户 ID

                  相关文章

                  最新文章

                  <small id='0aqTz'></small><noframes id='0aqTz'>

                  <tfoot id='0aqTz'></tfoot>

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

                    1. <legend id='0aqTz'><style id='0aqTz'><dir id='0aqTz'><q id='0aqTz'></q></dir></style></legend>
                        <bdo id='0aqTz'></bdo><ul id='0aqTz'></ul>