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

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

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

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

        如何使用 discord.py 事件处理程序 on_voice_state_upd

        时间:2023-10-11

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

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

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

                  <tbody id='TaJA5'></tbody>
                • <i id='TaJA5'><tr id='TaJA5'><dt id='TaJA5'><q id='TaJA5'><span id='TaJA5'><b id='TaJA5'><form id='TaJA5'><ins id='TaJA5'></ins><ul id='TaJA5'></ul><sub id='TaJA5'></sub></form><legend id='TaJA5'></legend><bdo id='TaJA5'><pre id='TaJA5'><center id='TaJA5'></center></pre></bdo></b><th id='TaJA5'></th></span></q></dt></tr></i><div id='TaJA5'><tfoot id='TaJA5'></tfoot><dl id='TaJA5'><fieldset id='TaJA5'></fieldset></dl></div>
                  本文介绍了如何使用 discord.py 事件处理程序 on_voice_state_update 仅在用户加入语音频道时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试学习如何通过 discord.py 制作一个不和谐的机器人,并希望添加一个功能,即每当另一个用户加入机器人的语音频道时,都会从机器人发送消息目前在.我不知道如何使用事件处理程序本身,也没有充分了解他们的文档来使用它.

                  I am trying to learn how to make a discord bot through discord.py and wanted to add a feature where a message would be sent from the bot whenever another user joined the voice channel that the bot is currently in. I do not know how to use the event handler itself and didn't understand their documentation enough to utilize it.

                  from discord.ext.commands import Bot 
                  client = Bot(command_prefix="!")
                  
                  @client.event
                  async def on_voice_state_update(before, after):
                      await client.say("Howdy")
                  

                  根据我对文档的有限理解,只要用户静音、耳聋、离开或加入频道,就应该使用事件处理程序.

                  From my limited understanding of the documentation, the event handler should be used whenever a user is muted, deafened, leaves, or joins a channel.

                  但是,即使我试图让它识别这些操作,它也会给我一个错误消息:

                  However, even when I tried to get it to recognize those actions it gave me an error message of:

                  Ignoring exception in on_voice_state_update
                  Traceback (most recent call last):
                    File "C:UsersSamPycharmProjectsFunBotProjectvenvlibsite-packagesdiscordclient.py", line 307, in _run_event
                      yield from getattr(self, event)(*args, **kwargs)
                    File "C:/Users/Sam/PycharmProjects/FunBotProject/my_bot2.py", line 63, in on_voice_state_update
                      await client.say("Xd ")
                    File "C:UsersSamPycharmProjectsFunBotProjectvenvlibsite-packagesdiscordextcommandsot.py", line 309, in _augmented_msg
                      msg = yield from coro
                    File "C:UsersSamPycharmProjectsFunBotProjectvenvlibsite-packagesdiscordclient.py", line 1145, in send_message
                      channel_id, guild_id = yield from self._resolve_destination(destination)
                    File "C:UsersSamPycharmProjectsFunBotProjectvenvlibsite-packagesdiscordclient.py", line 289, in _resolve_destination
                      raise InvalidArgument(fmt.format(destination))
                  discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType
                  

                  推荐答案

                  2020 年版本.请注意,我的代码在发送的消息方面表现不同.

                  A version working in 2020. Please not that my code behaves different in terms of the sent message.

                  from discord.ext.commands import Bot 
                  bot = commands.Bot(command_prefix='!')
                  
                  @bot.event
                  async def on_voice_state_update(member, before, after):
                      if before.channel is None and after.channel is not None:
                          if after.channel.id == [YOUR_CHANNEL_ID]:
                              await member.guild.system_channel.send("Alarm!")
                  

                  这篇关于如何使用 discord.py 事件处理程序 on_voice_state_update 仅在用户加入语音频道时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何编辑嵌入消息 - discord.py 下一篇:discord.py 机器人可以不区分大小写吗?

                  相关文章

                  最新文章

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

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

                        <bdo id='mImEA'></bdo><ul id='mImEA'></ul>
                    1. <tfoot id='mImEA'></tfoot>

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