【发布时间】:2021-03-11 17:34:26
【问题描述】:
所以,我有一个机器人可以通过一个非常简单的命令向用户发送 DM。我所做的只是“!DM @user message”,它会向他们发送消息。然而,人们有时会尝试用他们的问题来回复 DM 中的机器人,但机器人对此无能为力,我看不到他们的回复。有没有办法让我这样做,如果用户向机器人发送 DM,它会将他们的消息转发到我服务器中的某个频道(频道 ID:756830076544483339)。
如果可能,请有人告诉我,我必须使用什么代码才能在发送到我的频道 756830076544483339 的所有 DM 上转发它。
这是我当前的代码:
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 编码还是很陌生,所以请你写出我需要添加到脚本中的代码,而不是仅仅告诉我一些代码,因为我经常对此感到困惑那。谢谢!
【问题讨论】:
-
您必须使用
on_message事件来读取 DMS 中的传入消息。 discordpy.readthedocs.io/en/latest/api.html#discord.on_message
标签: python discord discord.py