有没有办法在discord.py中接收其他用户给我的建议

时间:2021-03-17 14:26:08

标签: python discord.py

我正在 discord.py 中制作一个机器人。我希望用户在他们的服务器中提出建议,然后这些建议会传达给我。我不知道这是否可能以及怎么可能。请考虑帮助我。到目前为止,我只有完全正常工作的正常建议命令的代码

@client.command()
    async def suggest(self, ctx, *,suggestion):

        
        await ctx.channel.purge(limit = 1)
        channel = discord.utils.get(ctx.guild.text_channels, name = 'suggestions')

        suggestEmbed = discord.Embed(colour = 0xFF0000)
        suggestEmbed.set_author(name=f'Suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
        suggestEmbed.add_field(name = 'New suggestion!', value = f'{suggestion}')

        message = await ctx.send(embed=suggestEmbed)

        await message.add_reaction('✅')
        await message.add_reaction('❌')

1 个答案:

答案 0 :(得分:2)

假设您是机器人的所有者。您可以通过 bot.owner_id 获取您的 ID。

async def suggest(self, ctx, *, suggestion):
     #make embed here
     owner = self.bot.get_user(self.bot.owner_id)
     await owner.send(embed=embed)

如果 get_user 不起作用

async def suggest(self, ctx, *, suggestion):
     #make embed here
     owner = await self.bot.fetch_user(self.bot.owner_id)
     await owner.send(embed=embed)

如果您不是机器人的所有者,只需在 get_user 中硬编码您的 ID

参考: