• <small id='mFph7'></small><noframes id='mFph7'>

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

      1. 如何正确解析我的 Discord 机器人中的标记用户?

        时间:2023-10-10
        <tfoot id='sAQH5'></tfoot>

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

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

                1. <legend id='sAQH5'><style id='sAQH5'><dir id='sAQH5'><q id='sAQH5'></q></dir></style></legend>
                    <tbody id='sAQH5'></tbody>
                2. 本文介绍了如何正确解析我的 Discord 机器人中的标记用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在向我的 Discord 机器人添加个人资料卡,但我遇到了一个问题.当有人键入 !profile @user 我不确定如何正确解析 @user 以便机器人知道要查找哪个个人资料卡.

                  I am adding profile cards onto my Discord bot, but I've come across one issue. When someone types !profile @user I am not sure how to properly parse for @user so the bot knows which profile card to lookup.

                  我首先解析 message.content,然后删除消息内容的前 9 个字符(始终是 !profile),但消息内容的其余部分返回看起来 < 的 user_id;@289583108183948460> 而不是用户的歧视.我曾尝试使用 re.sub 删除特殊字符(@、> 和 <),如下所示:

                  I first parse message.content and then remove the 9 first chars of the message content (which is always !profile) but the rest of the message content returns the user_id which looks <@289583108183948460> instead of the user's discrim. I have tried using re.sub to remove the special characters (@, >, and <) like this:

                  a = str(message.content[9:])
                  removeSpecialChars = re.sub("[!@#$%^&*()[]{};:,./<>?|`~-=_+]", " ", a)
                  print(removeSpecialChars)
                  

                  但是当我只想要数字时,奇怪的字符仍然存在,因此我可以轻松地在数据库中搜索它.我确信有更好的方法可以做到这一点,但我想不通.

                  But the weird characters are still there when I only want the number so I can search it in the database easily. I'm sure there's a way better way to do this though but I can't figure it out.

                  推荐答案

                  discord.py 的消息对象包含 Message.mentions 属性,因此您可以遍历 Member.以下是 async 和 的文档列表href="https://discordpy.readthedocs.io/en/rewrite/api.html#discord.Message.mentions" rel="nofollow noreferrer">重写.

                  discord.py's message objects include a Message.mentions attribute so you can iterate over a list of Member. Here are the doc listings for async and rewrite.

                  有了这个,你可以简单地迭代提及:

                  With this you can simply iterate over the mentions as so:

                  for member in ctx.message.mentions:
                      # do stuff with member
                  

                  你真正想要的

                  discord.py 允许您从带有 discord.Member 对象"nofollow noreferrer">类型提示.只需将以下内容添加到命令中

                  what you actually want

                  discord.py allows you to grab discord.Member objects from messages with type hinting. simply add the following to the command

                  @bot.command()
                  async def profile(ctx, member: discord.Member=None):
                      member = member or ctx.message.author
                  

                  这篇关于如何正确解析我的 Discord 机器人中的标记用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何仅在触发当前命令时使用命令? 下一篇:discord.py 嵌入 youtube 视频而无需粘贴链接

                  相关文章

                  最新文章

                3. <small id='ioc5l'></small><noframes id='ioc5l'>

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

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