您如何让 Discord 机器人读取发送给它的 DM? (discord.py)
How do you have a Discord bot read DMs sent to it? (discord.py)
我想出了一个方法给 DM 人,但我想知道他们通过 DM 回复机器人的内容,就好像机器人 "reads" 的 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")
我使用的方式与人们定义函数的方式不同,我使用更基本的命令方式。
感谢任何帮助!
这是一个简单的例子。我已将您现有的命令移动到实际的 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)
我想出了一个方法给 DM 人,但我想知道他们通过 DM 回复机器人的内容,就好像机器人 "reads" 的 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")
我使用的方式与人们定义函数的方式不同,我使用更基本的命令方式。
感谢任何帮助!
这是一个简单的例子。我已将您现有的命令移动到实际的 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)