3

我想出了一种与 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")

与人们定义函数的方式相反,我用一种不同的方式来做这件事,我使用一种更基本的方式来制作命令。

任何帮助表示赞赏!

4

1 回答 1

4

这是一个简单的例子。我已经将您现有的命令移动到一个实际的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)
于 2018-06-19T23:53:44.777 回答