【问题标题】:Sending a message specifying a channel / Python Discord发送指定频道/Python Discord 的消息
【发布时间】:2019-03-18 22:11:30
【问题描述】:
@Bot.command(pass_context = True)
async def xsend(ctx, *, message):
    await Bot.delete_message(ctx.message)
    await Bot.send_message(discord.Object(id='408104999038746635'), message)

我有这个命令可以根据其 ID 向特定频道发送消息,但我希望能够选择我想将此消息发送到哪个频道,例如:

xsend "#namechannel" "mymessage"

我该怎么办?

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    您可以使用频道converter 自动将频道参数转换为discord.Channel 对象:

    @bot.command(pass_context=True)
    async def xsend(ctx, channel: discord.Channel, *, message):
        await bot.delete_message(ctx.message)
        await bot.send_message(channel, message)
    

    【讨论】:

      猜你喜欢
      • 2021-03-24
      • 2021-10-28
      • 2020-10-01
      • 2020-04-07
      • 2023-03-27
      • 2020-07-06
      • 2021-01-10
      • 2019-03-01
      • 2020-05-18
      相关资源
      最近更新 更多