Mic*_*ett 3 python bots discord discord.py
我正在制作一个简单的不和谐机器人,并试图找出消息的渠道和发送者,因此例如当某些人输入时,d!salute blah它会回复"<SENDER> saluted blah!",并附有图像。我目前只知道如何使用client.say,它为我找到了频道。我想知道的是如何检索发送消息的通道以及命令的发送者。谢谢
您需要传递上下文才能访问消息对象。
@client.command(pass_context = True) #passing context
async def salute(ctx): #context gets passed into the first parameter
print(str(ctx.message.author))
print(str(ctx.message.channel)
print(str(ctx.message.content))
Run Code Online (Sandbox Code Playgroud)
等等,您可以在文档中找到有关消息对象的更多信息