[英](Discord.py) Make my Bot only Respond to DM's
所以我设法让我的 Bot 工作的基础知识很好。 但是,当我尝试发送一条消息时,例如执行/ping
时,机器人会回复它,而不管命令在哪个频道中执行,包括 DM,然后我编写了一条语句,使其仅响应某些 Discord 频道中的命令在服务器上。 这似乎确实有效,但是,当我尝试将通道数组更改为discord.DMChannel
时,这似乎无效。 有人可以帮我解决这个问题吗?
channels = ["general"]
if str(message.channel) in channels:
if message.content == "/ping":
await message.channel.send("Pong")
但是如果我把它改成这样:
channels = [discord.DMChannel]
if str(message.channel) in channels:
if message.content == "/ping":
await message.channel.send("Pong")
机器人不响应 DMChannel 消息。
您可以尝试设置机器人意图,但请记住这些会影响整个机器人,而不仅仅是一个命令。
...
my_intents = discord.Intents.default()
my_intents.guild_messages = False # turn off messages from guilds, so you only get messages from DM channels
# optionally turn on members or presences here if you need them
client = discord.Client(..., intents=my_intents) # or discord.Bot() or whatever
...
你可以简单地做
await ctx.author.send
它只会在 dms 中发送响应。 它也可以在频道中使用,但它会在 dms 中发送响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.