问题描述
因此,我有一个机器人可以通过一个非常简单的命令向用户发送DM.我所要做的只是!DM @user message";然后向他们发送消息.但是,人们有时会尝试向DM中的bot提问,但bot对此无能为力,我看不到他们的答复.我有办法做到这一点,以便如果用户将DM发送给漫游器,它将把他们的消息转发到我服务器中的某个信道(信道ID:756830076544483339).
So, I've got a bot that can send a user a DM via a very simple command. All I do is "!DM @user message" and it sends them the message. However, people sometimes try responding to the bot in DMs with their questions, but the bot does nothing with that, and I cannot see their replies. Would there be a way for me to make it so that if a user sends a DM to the bot, it will forward their message to a certain channel in my server (Channel ID: 756830076544483339).
如果可能的话,请告诉我在发送给我的所有DM到756830076544483339的DM上,我必须使用什么代码来转发它.
If possible, please can someone tell me what code I would have to use to make it forward on all DMs sent to it to my channel 756830076544483339.
这是我当前的代码:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
activity = discord.Game(name="DM's being sent", type=3)
await bot.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name="Pokemon Go Discord Server!"))
print("Bot is ready!")
@bot.command()
async def DM(ctx, user: discord.User, *, message=None):
message = message or "This Message is sent via DM"
await user.send(message)
await ctx.send('DM Sent Succesfully.')
谢谢!
注意:我对discord.py编码还很陌生,所以请您实际写出我需要添加到脚本中的代码,而不是仅仅告诉我其中的一点,因为我经常对此感到困惑那.谢谢!
Note: I'm still quite new to discord.py coding, so please could you actually write out the code I would need to add to my script, rather than just telling me bits of it, as I often get confused about that. Thank you!
推荐答案
您正在寻找的是 on_message
事件
@bot.event
async def on_message(message):
# Checking if its a dm channel
if isinstance(message.channel, discord.DMChannel):
# Getting the channel
channel = bot.get_channel(some_id)
await channel.send(f"{message.author} sent:\n```{message.content}```")
# Processing the message so commands will work
await bot.process_commands(message)
这篇关于如何使我的机器人将发送给它的DM转发到某个频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!