python - 建议命令在 discord.py 中不起作用
问题描述
我目前正在discord.py中编写一个机器人,它执行诸如kick之类的mod命令。我正在尝试制作一个命令,您可以向服务器建议一些东西,就像他们制作一个称为suggest-channel的频道一样,当他们执行命令它将其发送到该通道。我有一个命令可以向特定频道发送消息以获取机器人建议,但这是我得到的最接近的。下面是我在 cogs 中的建议命令的代码,是的,我使用命令处理。
@commands.command()
async def suggest(self ,ctx , *, suggestion):
embed = discord.Embed(title=f"Suggestion from {ctx.author.name}", description=suggestion, color=discord.Color.blue())
embed.set_footer(text=f"Suggestion created by {ctx.author}")
channel = discord.utils.get(message.server.channels, name="suggestion-channel")
message = await channel.send(embed=embed)
await message.add_reaction("✅")
await message.add_reaction("❌")
await ctx.message.delete()
await ctx.send("Thank you for your suggestion!")
解决方案
首先,您没有在on_message
事件中获取频道,或者使用用户的消息来获取服务器的频道。您必须替换message
为ctx
. 其次,ctx.server
自 discord.py 迁移后不再有效。它现在被称为ctx.guild
,您可以在他们的文档中阅读。
channel = discord.utils.get(message.server.channels, name="suggestion-channel")
# change this to:
channel = discord.utils.get(ctx.guild.channels, name="suggestion-channel")
否则,如果您发现任何其他命令都不起作用,则您可能尚未处理您的on_message
事件。您可以查看有关如何解决此问题的问题:
推荐阅读
- c - 将 char * 数组中的字符串分配给另一个 char * 数组
- django - 在 django 模板中绘制图形
- java - 没有为范围名称“重新启动”注册范围
- eclipse - Sonarlint Eclipse - 停用规则列表
- r - 使用 poliregions 修改 BED
- ruby-on-rails - 如何为 gem 提供广泛的 Rails 版本
- maven - 詹金斯管道中的 Maven 生命周期 - 如何最好地分离职责?
- apache-spark - 找不到参数 sparkSession 的隐式值
- pointers - 在 Intel fortran 中使用大尺寸指针数组时出现溢出错误
- java - lambda 表达式中的参数类型不兼容,预期为 Object,但发现为 Boolean