discord.py - 运行“commands.group()”的 discord.py 在针对第二个命令时发送帮助命令
问题描述
很难得到完美的标题,但差不多。得到它!!changelog
是主要命令,这将发送所有可用命令的列表,但我得到的问题是。每当我运行!!changelog message <text>
命令时,都会显示预设的“帮助”消息。
每当发送消息时,我只希望它说“您的消息已发送”之类的内容
这是我的代码:
@commands.group(invoke_without_command=True)
async def changelog(self, ctx):
await ctx.send('Available Setup Commands: \nSet Channel: <#channel>\nChangelog Message: <message>')
@changelog.command()
async def channel(self, ctx, channel: discord.TextChannel):
if ctx.message.author.guild_permissions.administrator:
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(
f'SELECT channel_id FROM main WHERE guild_id = {ctx.guild.id}')
result = cursor.fetchone()
if result is None:
sql = ('INSERT INTO main(guild_id, channel_id) VALUES(?,?)')
val = (ctx.guild.id, channel.id)
await ctx.send(f'Channel has been set to {channel.mention}')
elif result is not None:
sql = ('UPDATE main SET channel_id = ? WHERE guild_id = ?')
val = (channel.id, ctx.guild.id)
await ctx.send(f'Channel has been updated to {channel.mention}')
cursor.execute(sql, val)
db.commit()
cursor.close()
db.close()
@changelog.command()
async def message(self, ctx, *, text):
if ctx.message.author.guild_permissions.manage_messages:
est = timezone('EST')
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(f'SELECT channel_id FROM main WHERE 1')
channel = cursor.fetchone()
channel_id = self.client.get_channel(int(channel[0]))
message = text.capitalize()
embed = discord.Embed(
title="Changelog", description=f"● {message}", color=0)
embed.set_footer(
text=f'Published: {datetime.now(est).strftime("%Y-%m-%d %H:%M:%S")}')
await channel_id.send(embed=embed)
cursor.close()
db.close()
解决方案
你可以ctx.invoked_subcommand
用来检查你是否在你的组中运行一个子命令:
async def changelog(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.send('Available Setup Commands: \nSet Channel <#channel>\nChangelog Message: <message>')
推荐阅读
- python - django prefetch_related across mutliple one-to-many relations with filtering conditions
- python - “ImmutableDenseNDimArray”对象没有属性“could_extract_minus_sign”
- mysql - Getting older balances of credit and debit accounts from transactions table for users in bulk
- spring-boot - 使用 Spring WebFlux 和 OAuth 2.0 登录时如何注销?
- c# - 我们没有在 csx 脚本中明确指定变量类型并始终使用 var 是否有特定原因?
- ios - 如何手动设置 AVPlayerViewController 的开始和结束时间
- python - Jupyter Notebook 上的 import librosa 命令问题
- matlab - Matlab 视频阅读器 - 在对象上绘制磁盘
- reactjs - 在我更新我的 mac OS 后,Watchman 不会让我启动任何我的 react native 项目
- python - 用python播放.wav文件的随机片段