gpt4 book ai didi

python - Discord.py - 使用特定消息回复 DM

转载 作者:行者123 更新时间:2023-12-02 02:39:49 26 4
gpt4 key购买 nike

试图让我的机器人回复私信“这是一个私信”,但没有成功,这是我的代码:

@client.event
async def on_message(message):
if message.guild == null:
await message.channel.send('this is a dm')
else:
pass

我也尝试过使用这个:

@client.event
async def on_message(message):
if isinstance(message.channel, discord.channel.DMChannel):
await ctx.send('This is a DM')

在最后一个中,由于上下文 (ctx),我收到错误

最佳答案

您发送的第一个代码使用了 null,这在 Python 中甚至不是一个东西。第二个有点不必要,用这个代替:

@client.event
async def on_message(message):
if not message.guild:
await message.channel.send('this is a dm')

关于python - Discord.py - 使用特定消息回复 DM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63802655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com