首页 文章

discord.py和私信

提问于
浏览
-1

我试图在phyton上制作discord-bot . 虽然我已经理解了discord API,但是我无法让机器人在私人邮件中向服务器成员发送消息 . 请问你能帮帮我吗

if message.content.startswith(myname + '!btcprice'):
    print('[command]: btcprice ')
    btc_price_usd, btc_price_rub = get_btc_price()
    msg = 'USD: ' + str(btc_price_usd) + ' | RUB: ' + str(btc_price_rub)
    await client.send_message(message.channel, msg)

1 回答

  • 0

    我假设你从 on_message 事件中调用它,在这种情况下发送PM你可以从 message.author 获得 member 对象 . 你可以用这个PM来管理用户 .

    @client.event
    async def on_message(message):
        if message.content.startswith(myname + '!btcprice'):
            print('[command]: btcprice ')
            btc_price_usd, btc_price_rub = get_btc_price()
            msg = 'USD: ' + str(btc_price_usd) + ' | RUB: ' + str(btc_price_rub)
            await client.send_message(message.author, msg)
    

相关问题