本文介绍了您如何让Discord机器人读取发送给它的DM?(discord.py)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出了一种方法来管理DM的人,但是我想知道他们通过DM向机器人说了些什么,就像机器人读取"了DM,然后将其转发到某个不和谐的频道中一样.我的服务器,或者甚至更好,将它DM给我.

I've come up with a way to DM people, but I want to know what they say back to the bot through DMs, as if the bot "reads" the DM, and then forwards it to some channel in a discord server of mine, or, even better, DM it to me.

这是我的起始代码:

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")

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

I do it a different way contrary to how people do it with defining functions, I use a more basic way of making commands.

感谢您的帮助!

推荐答案

下面是一个简单的示例.我已经将您现有的命令移至实际的 Command 对象中,因此转发逻辑是 on_message

Here's a quick example. I've moved your existing command into an actual Command object, so the forwarding logic is the only thing in 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)

这篇关于您如何让Discord机器人读取发送给它的DM?(discord.py)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 01:51