【问题标题】:How to make embeds through dm's Discord.py Rewrite如何通过 dm 的 Discord.py Rewrite 进行嵌入
【发布时间】:2021-07-20 03:28:25
【问题描述】:

我正在处理 discord.py rewrite 中的机器人,并试图发出命令以通过 dm 进行嵌入。问题是机器人不等待消息。这是我的代码谢谢!

@client.command()
async def c_embed(ctx):
  user = ctx.author
  perms = ctx.author.permissions_in(ctx.channel)
  if perms.administrator:
    em = discord.Embed(description='What would you like the title to be?', color = discord.Colour.red())
    await user.send(embed=em)
    msg = await client.wait_for('message')
    title = msg.content
    em = discord.Embed(description='What would you like the Description to be?', color = discord.Colour.red())
    await user.send(embed=em)
    msg = await client.wait_for('message')
    desc = msg.content
    em = discord.Embed(title = "**Confirm Channel**", description = "Choose a channel for this msg to be in. Put Channel ID")
    em = discord.Embed(title=title, description=desc,color=discord.Colour.red())
    channel = msg.content
    await ctx.channel.send(embed=em)
    return

【问题讨论】:

  • 这里有什么问题?你只是放了一堆代码,我们应该用它做什么?任何错误/追溯?结果是什么?预期的结果是什么。请看how to ask
  • 测试您的代码后,我没有看到任何错误。请更详细地解释,正如 Łukasz Kwieciński 所说,出了什么问题。
  • 我运行它时没有错误。但是当我使用该命令时,它不会等待用户消息。
  • 可能是用户不允许私信
  • 不,我在自己身上测试命令,我已经打开了我的 dm。

标签: python-3.x discord.py


【解决方案1】:

由于大量阅读文档和测试,现在已经解决了 而不是仅仅等待响应,机器人等待用户响应。

通过使用:

msg = await client.wait_for('message', check = lambda message: message.author == ctx.author)

它只接受作者的回复,使其在 dm 中等待。

@client.command()
async def c_embed(ctx):
  user = ctx.author
  perms = ctx.author.permissions_in(ctx.channel)
  if perms.administrator:
    em = discord.Embed(description='What would you like the title to be?', color = discord.Colour.red())
    await user.send(embed=em)
    msg = await client.wait_for('message', check=lambda message: message.author == ctx.author)
    title = msg.content
    em = discord.Embed(description='What would you like the Description to be?', color = discord.Colour.red())
    await user.send(embed=em)
    msg = await client.wait_for('message', check=lambda message: message.author == ctx.author)
    desc = msg.content
    em = discord.Embed(title = "**Confirm Channel**", description = "Choose a channel for this msg to be in. Put Channel ID", color = discord.Colour.red())
    await user.send(embed=em)
    msg = await client.wait_for('message', check=lambda message: message.author == ctx.author)
    channel = msg.content
    em = discord.Embed(title=title, description=desc,color=discord.Colour.red())
    await ctx.channel.send(embed=em)
    return

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-23
    • 2020-05-31
    • 2021-03-04
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 2020-10-10
    • 2021-11-21
    相关资源
    最近更新 更多