您如何发送Discord机器人读取的DM? (discord.py)

时间:2018-06-19 22:08:59

标签: python-3.6 discord.py dm

我想出了一种向DM人员发送消息的方法,但是我想知道他们通过DM向机器人说的是什么,好像该机器人“读取”了DM,然后将其转发到某个不和谐的频道中我的服务器,或者甚至更好,将它DM给我。

这是我的起始代码:

if message.content.startswith("!dm"):
    if message.author.id == "[YOUR ID HERE]":
        memberID = "ID OF RECIPIENT"
        server = message.server
        person = discord.Server.get_member(server, memberID)
        await client.delete_message(message)
        await client.send_message(destination = person, content = "WHAT I'D LIKE TO SAY TO THEM")

我用与定义函数相反的方式来做,相反,我使用了一种更基本的命令制作方式。

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

这是一个简单的例子。我已将您现有的命令移至实际的Command对象中,因此转发逻辑是on_message

中的唯一内容
from discord.ext import commands

bot = commands.bot('!')

# I've moved the command out of on_message so it doesn't get cluttered
@bot.event
async def on_message(message):
    channel = bot.get_channel('458778457539870742')
    if message.server is None and message.author != bot.user:
        await bot.send_message(channel, message.content)
    await bot.process_commands(message)

# This always sends the same message to the same person.  Is that what you want?
@bot.command(pass_context=True)
@commands.is_owner()  # The account that owns the bot
async def dm(ctx):
    memberID = "ID OF RECIPIENT"
    person = await bot.get_user_info(memberID)
    await bot.send_message(person, "WHAT I'D LIKE TO SAY TO THEM")
    await bot.delete_message(ctx.message)