DM用户通过斜杠命令在discord.py?



我用斜杠命令使我的机器人更酷,我想添加一个功能,其中机器人dm斜杠命令的用户。我发现了这个问题,但这对我来说完全没用,因为我使用Python,而它使用JS。

@tree.command(name="dm", description="a command to DM", guild=discord.Object(id=ID)) #slashy
async def dm(interaction=discord.Interaction):
user = discord.Object(bot.user.id)
await user.send("This is a test message")

这不起作用,因为discord.Object object has no attribute 'send'

您可以使用.create_dm()方法:

user = await interaction.user.create_dm()
await user.send("This is a test message")

我还没有测试过这个,但它应该适用于你。

最新更新