【问题标题】:How to send name of someone in Discord with bot in Python如何使用 Python 中的机器人在 Discord 中发送某人的姓名
【发布时间】:2021-11-16 12:33:46
【问题描述】:

我正在编写我的 Python Discord 机器人,在询问时,

Warn <@anyone>

应将 DM 发送至 Discord 中的@anyone

到目前为止,我已经写了,

if message.content.startswith('Warn '):

现在我想将整个消息转换为字符串格式,然后从中删除“警告”。这样我就很容易得到@anyone 的名字。但我无法做到这一点。此外,我不知道是否可以转换为String。

有人能回答我的问题吗?感谢您阅读我的问题。

【问题讨论】:

  • 你不应该真正使用 on_message 命令,考虑使用commands extension。它可以让你在 3 行中完成这个命令

标签: python discord discord.py mention


【解决方案1】:

通过@user来获得使用,这就是我的做法

@client.command() #to start the command
async def warn(ctx, member : discord.member): #name and import ctx / other things too 
       await ctx.send(f"{member.mention}")

如果我做错了,请告诉我它有点

【讨论】:

  • 不确定“命名并导入 ctx”是什么意思,没有什么要导入的 - ctx 只是一个参数。如果您没有将其键入为 commands.Context(在您的示例中没有这样做),那么就没有可导入的内容。
猜你喜欢
  • 1970-01-01
  • 2023-02-26
  • 2021-10-01
  • 2017-12-05
  • 2021-04-10
  • 2021-06-13
  • 2023-04-03
  • 2020-09-14
  • 2020-06-29
相关资源
最近更新 更多