Discord.py bot.send_message()不会转到它所调用的频道

问题描述 投票:0回答:1

我制作了一个名为JMKBot(版本4.0)的Discord.py Discord机器人。当我使用bot.say()函数时,它会在用户调用它的任何地方说出它

@bot.command()
async def example():
    bot.say("example")
    print("example command run!")

会在我称之为例子的同一频道中说出来。

但是bot.send_message()需要一个目标变量,我不能让它自动转到命令所在的通道。

如何将目标变量转到命令所在的通道?

python python-3.x discord discord.py
1个回答
1
投票
@bot.command(pass_context=True)
async def example(ctx):
    await bot.send_message(ctx.message.channel, 'Example')

将上下文传递给命令,然后从message属性中获取通道。

© www.soinside.com 2019 - 2024. All rights reserved.