【问题标题】:How to scan if a channel is dmchannel as a response by the user如何扫描频道是否为 dmchannel 作为用户的响应
【发布时间】:2021-08-11 07:09:01
【问题描述】:

所以我正在制作一个机器人,比如向用户提问,我遇到了以下问题,我安装了所有必需的库并且它们可以工作


@client.command()
async def partner(ctx):
  def check(m):
    if m.channel == discord.channel.DMChannel and m.author == ctx.author:
      return m.author == ctx.author and m.channel == discord.DMChannel
  x = ["hello","hi"]
  for i in x:
    msg.content=msg.content.lower()
    await  discord.DMChannel.send(ctx.author,i)
    try:
      msg = await client.wait_for('message',timeout=60.0, check=check)
    except asyncio.TimeoutError:
      await discord.DMChannel.send(ctx.author,"Please dont take that long for your answer, be quicker next time")
      return
    else:
      if msg.content =="cancel":
        await discord.DMChannel.send(ctx.author,"Ok Cancelling partnership, you can still re-apply")
       return
    answers.append(msg.content)

但问题是,如果您在我的代码缩进中看到任何错误,我实际上也无法获得我想要的输出,因此我正在移动设备上执行此操作,并且。我检查了互联网上的所有东西,但没有一个对我有帮助,我很感谢你能给我的任何帮助

编辑后: 下面的答案是正确的,如果你们都想使用它,那就这样做吧

  def check(m):
    if m.author == ctx.author and isinstance(m.channel,discord.DMChannel):
      return m.author == ctx.author

它有效。非常感谢您分享答案

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    您可以像这样使用频道检查

    if isinstance(channel, discord.DMChannel):
    

    在向用户发送 dm 时也使用

    await ctx.author.send("Test")
    

    【讨论】:

    • 那么当条件为真时我应该返回什么,请告诉我检查者
    • 当条件为True 时,频道为DM,随心所欲。
    • 非常感谢,解决了我的问题,效果很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2015-12-01
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    相关资源
    最近更新 更多