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

        <bdo id='75SBN'></bdo><ul id='75SBN'></ul>
    2. <legend id='75SBN'><style id='75SBN'><dir id='75SBN'><q id='75SBN'></q></dir></style></legend>

      <small id='75SBN'></small><noframes id='75SBN'>

      Python - DM 一个用户 Discord 机器人

      时间:2023-09-11

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

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

                问题描述

                我正在使用 Python 开发 User Discord Bot.如果 bot 所有者键入 !DM @user,那么 bot 将 DM 所有者提到的用户.

                I'm working on a User Discord Bot in Python .If the bot owner types !DM @user then the bot will DM the user that was mentioned by the owner.

                @client.event
                async def on_message(message):
                    if message.content.startswith('!DM'):
                        msg = 'This Message is send in DM'
                        await client.send_message(message.author, msg)
                

                推荐答案

                最简单的方法是使用 discord.ext.commands 扩展.这里我们使用 converter 来获取目标用户,和一个 keyword-only 参数发送给他们的可选消息:

                The easiest way to do this is with the discord.ext.commands extension. Here we use a converter to get the target user, and a keyword-only argument as an optional message to send them:

                from discord.ext import commands
                import discord
                
                bot = commands.Bot(command_prefix='!')
                
                @bot.command(pass_context=True)
                async def DM(ctx, user: discord.User, *, message=None):
                    message = message or "This Message is sent via DM"
                    await bot.send_message(user, message)
                
                bot.run("TOKEN")
                


                对于较新的 1.0+ 版本的 discord.py,您应该使用 send 而不是 send_message

                from discord.ext import commands
                import discord
                
                bot = commands.Bot(command_prefix='!')
                
                @bot.command()
                async def DM(ctx, user: discord.User, *, message=None):
                    message = message or "This Message is sent via DM"
                    await user.send(message)
                
                bot.run("TOKEN")
                

                这篇关于Python - DM 一个用户 Discord 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 discord.py 中使用 cogs? 下一篇:Discord.py:on_member_join 突然停止工作

                相关文章

                最新文章

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

              2. <legend id='pHnUN'><style id='pHnUN'><dir id='pHnUN'><q id='pHnUN'></q></dir></style></legend>

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

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