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('❌')
解决方案
假设您是机器人的所有者。你可以得到你的身份证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
参考:
推荐阅读
- python - 使用棉花糖序列化 sqlalchemy hybrid_property
- javascript - 获取语言环境的货币符号
- r - Fill heatmap missing values
- wpf - Button foreground doesn't change when content is StackPanel
- html - R Webscraping RCurl 和 httr 内容
- java - org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“customUserDetailsService”的bean时出错
- python - Pycharm 运行将当前工作目录添加到 PYTHONPATH 的代码
- zigbee - Zigbee AF 帧与 ZCL 命令
- machine-learning - 机器学习中面向未来的功能扩展?
- parsing - antlr4 协助