首页 > 解决方案 > 有没有办法在 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('❌')

标签: pythondiscord.py

解决方案


假设您是机器人的所有者。你可以得到你的身份证bot.owner_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

参考:


推荐阅读