【问题标题】:Why will my discord bot not send a message in a channel discord.py为什么我的不和谐机器人不会在频道 discord.py 中发送消息
【发布时间】:2021-09-11 20:40:07
【问题描述】:

当我告诉它在频道中发送消息时,我的 python discord bot 不断出错

@client.command()
async def log(ctx, msg):
channel = client.get_channel(852610465871036416)
await channel.message.send(msg)

PS:现在修复了

【问题讨论】:

  • 你在说哪些错误?只需使用channel.send(msg)

标签: python discord discord.py bots


【解决方案1】:

试试这个:

@client.command()
async def log(ctx, msg):
  await ctx.send(msg)

我很确定您需要使用 ctx.send

【讨论】:

  • 如果您有任何问题,请发表评论
【解决方案2】:

Tortle.py 是完全正确的,但是,您可以使用多种形式的 ctx.___("stuff") 。第一个也是最简单的例子是 ctx.send("stuff") ,这将在用户调用函数的通道中发送“东西”(机器人正在做的事情。)

你也可以ctx.author.send 这将私信(直接消息)调用该函数的作者。

您也可以ctx.reply 这将回复用户发送的消息。

我希望你觉得这很有用,并随时喜欢这个消息以获得任何额外的支持!

【讨论】:

    【解决方案3】:

    在最后一行

    await channel.message.send(msg)
    

    ?
    试试看

    await channel.send(msg)
    

    【讨论】:

      【解决方案4】:
      @client.command()
      async def log(ctx, message):
         await ctx.get_channel(852610465871036416).send(“your message”)
      

      这样就可以了

      【讨论】:

        猜你喜欢
        • 2021-11-30
        • 1970-01-01
        • 2020-10-25
        • 2021-08-14
        • 2020-12-23
        • 2020-12-18
        • 2021-06-01
        • 2022-01-09
        • 2021-05-08
        相关资源
        最近更新 更多