Use message replies when replying to commands

This commit is contained in:
Elnath 2021-02-09 23:34:09 +01:00
parent 4176666cb2
commit 4a656685c0
1 changed files with 27 additions and 27 deletions

View File

@ -52,7 +52,7 @@ class VocalMaisBot(commands.Cog):
if ctx.author.guild_permissions.administrator or ctx.author == self.owner:
return True
else:
await ctx.send(f":dragon_face: Only an administrator can control me!")
await ctx.reply(f":dragon_face: Only an administrator can control me!")
raise discord_utils.CheckFailDoNotNotify
def get_command_usage_message(self, command: commands.Command, prepend = "Usage: ") -> str:
@ -62,29 +62,29 @@ class VocalMaisBot(commands.Cog):
@commands.Cog.listener()
async def on_command_error(self, ctx: commands.Context, error: commands.CommandError):
if isinstance(error, commands.CommandNotFound):
return await ctx.send(f":x: The requested command does not exist")
return await ctx.reply(f":x: The requested command does not exist")
elif isinstance(error, commands.MissingRequiredArgument):
return await ctx.send(f":x: Missing required argument {error.param}. {self.get_command_usage_message(ctx.command)}")
return await ctx.reply(f":x: Missing required argument {error.param}. {self.get_command_usage_message(ctx.command)}")
elif isinstance(error, commands.TooManyArguments):
return await ctx.send(f":x: too many arguments for command {ctx.command}. {self.get_command_usage_message(ctx.command)}")
return await ctx.reply(f":x: too many arguments for command {ctx.command}. {self.get_command_usage_message(ctx.command)}")
elif isinstance(error, commands.BadArgument):
if hasattr(error, "argument"):
return await ctx.send(f":x: I could not correctly understand argument {error.argument}. {self.get_command_usage_message(ctx.command)}")
return await ctx.reply(f":x: I could not correctly understand argument {error.argument}. {self.get_command_usage_message(ctx.command)}")
else:
return await ctx.send(f":x: I could not correctly understand one of the arguments. {self.get_command_usage_message(ctx.command)}")
return await ctx.reply(f":x: I could not correctly understand one of the arguments. {self.get_command_usage_message(ctx.command)}")
elif isinstance(error, commands.ArgumentParsingError):
return await ctx.send(f":x: Error when parsing the command: {error}")
return await ctx.reply(f":x: Error when parsing the command: {error}")
elif isinstance(error, commands.CheckFailure):
if isinstance(error, discord_utils.CheckFailDoNotNotify): # A check failed, but the check function asked that we do not notify the user
return
else:
return await ctx.send(f":x: this command can not be run: {error}")
return await ctx.reply(f":x: this command can not be run: {error}")
else:
logger.error(f"Error when running command '{ctx.message.content}' by {discord_utils.to_string(ctx.author)} in {discord_utils.to_string(ctx.guild)}", exc_info = error)
if isinstance(error, commands.CommandInvokeError):
await ctx.send(f":x: There was an error during the command execution :dizzy_face:")
await ctx.reply(f":x: There was an error during the command execution :dizzy_face:")
else:
await ctx.send(f":x: There was an error with the command :dizzy_face:")
await ctx.reply(f":x: There was an error with the command :dizzy_face:")
def cog_check(self, ctx: commands.Context):
# We silently ignore messages from bots, since we do not want bots to command us
@ -102,14 +102,14 @@ class VocalMaisBot(commands.Cog):
command_elements = [str(cmd) for cmd in ctx.command.parents] + [ctx.command.name] # In case of nested groups
help_message = f"Type `@{self.bot.user.display_name} help {' '.join(command_elements)}` for help"
if ctx.subcommand_passed is None: # The user did not pass a subcommand
await ctx.send(f":x: Subcommand expected. {help_message}")
await ctx.reply(f":x: Subcommand expected. {help_message}")
else:
await ctx.send(f":x: The requested subcommand does not exist. {help_message}")
await ctx.reply(f":x: The requested subcommand does not exist. {help_message}")
raise discord_utils.CheckFailDoNotNotify()
@commands.command(help = "See if I am alive")
async def ping(self, ctx: commands.Context):
await ctx.send(":ping_pong:")
await ctx.reply(":ping_pong:")
@commands.group(
"guild",
@ -126,14 +126,14 @@ class VocalMaisBot(commands.Cog):
# Retrieving the channel
channel = self.bot.get_channel(channel_id)
if channel is None or channel.guild != ctx.guild:
return await ctx.send(f"I could not find a channel with id {channel_id} :cry:")
return await ctx.reply(f"I could not find a channel with id {channel_id} :cry:")
# Adding the channel to the list of watched channels (if needed)
has_been_added = self.channels_config.add_channel_to_watched(ctx.guild, channel)
if has_been_added:
await ctx.send(f":white_check_mark: I am now watching {channel.name}")
await ctx.reply(f":white_check_mark: I am now watching {channel.name}")
else:
await ctx.send(":thumbsup: I was already watching this channel")
await ctx.reply(":thumbsup: I was already watching this channel")
@guild_subcommands.command("forget", help = "Make me stop watching a voice channel")
async def forget_channel(self, ctx: commands.Context, channel_id: int):
@ -148,9 +148,9 @@ class VocalMaisBot(commands.Cog):
has_been_removed = self.channels_config.remove_channel_from_watched(ctx.guild, channel)
if has_been_removed:
await ctx.send(f":white_check_mark: I am no longer watching {channel_name}")
await ctx.reply(f":white_check_mark: I am no longer watching {channel_name}")
else:
await ctx.send(f":thumbsup: I already was not watching {channel_name}")
await ctx.reply(f":thumbsup: I already was not watching {channel_name}")
@guild_subcommands.command("list", help = "List watched channels")
async def list_watched_channels(self, ctx: commands.Context):
@ -163,16 +163,16 @@ class VocalMaisBot(commands.Cog):
answer_lines.append(f":eyes: {channel.name} ({channel_id})")
else:
answer_lines.append(f":ninja: <deleted channel> ({channel_id})")
await ctx.send(embed = discord.Embed(title = "I am watching the following channels", description = "\n".join(answer_lines)))
await ctx.reply(embed = discord.Embed(title = "I am watching the following channels", description = "\n".join(answer_lines)))
else:
await ctx.send(f":see_no_evil: I am not watching any voice channel! Do not hesitate to add some by running {self.get_command_usage_message(self.register_channel, '')}")
await ctx.reply(f":see_no_evil: I am not watching any voice channel! Do not hesitate to add some by running {self.get_command_usage_message(self.register_channel, '')}")
@guild_subcommands.command("clear", help = "Make me stop watching all channels")
async def clear_watched_channels(self, ctx: commands.Context):
await self.check_is_administrator_or_owner(ctx)
self.channels_config.clear_watched_channels(ctx.guild)
await ctx.send(":white_check_mark: I am no longer watching any channel")
await ctx.reply(":white_check_mark: I am no longer watching any channel")
@commands.group(
"name",
@ -190,34 +190,34 @@ class VocalMaisBot(commands.Cog):
async def set_user_default_channel_name(self, ctx: commands.Context, *name_elements: str):
# Verify that the given name does not mention anyone by checking the message mentions
if len(set(ctx.message.mentions) - {self.bot.user}) > 0:
await ctx.send(":no_entry: User mentions are not allowed in channel names. Use {user} if you want to include your name.")
await ctx.reply(":no_entry: User mentions are not allowed in channel names. Use {user} if you want to include your name.")
return
name = " ".join(name_elements)
if len(name) == 0:
await ctx.send(f":x: Missing channel name! {self.get_command_usage_message(ctx.command)}")
await ctx.reply(f":x: Missing channel name! {self.get_command_usage_message(ctx.command)}")
raise discord_utils.CheckFailDoNotNotify
self.channels_config.set_user_channel_name(ctx.guild, ctx.author, discord_utils.voice_channel_safe_name(name))
self.channels_config.save_to_file()
# We escape the markdown from the channel name when sending the message because for now discord does not support markdown in channel names,
# so we do not want the users to get their hopes up by seeing markdown working in the message
await ctx.send(f":white_check_mark: The default name for your channels has been set! If you create one now, it will appear as {discord_utils.voice_channel_safe_name(name, user_name_replacement = ctx.author.display_name, escape_markdown = True)}")
await ctx.reply(f":white_check_mark: The default name for your channels has been set! If you create one now, it will appear as {discord_utils.voice_channel_safe_name(name, user_name_replacement = ctx.author.display_name, escape_markdown = True)}")
@default_channel_name_subcommands.command("get", help = "See what the default name for your voice channels is")
async def get_user_default_channel_name(self, ctx: commands.Context):
channel_name = self.channels_config.get_user_channel_name(ctx.guild, ctx.author)
if channel_name is None:
await ctx.send(":person_shrugging: You have not set a special name for your voice channels")
await ctx.reply(":person_shrugging: You have not set a special name for your voice channels")
else:
channel_name = discord_utils.voice_channel_safe_name(channel_name, user_name_replacement = ctx.author.display_name, escape_markdown = True)
await ctx.send(f":memo: If you create a voice channel right now, it will be named like this: {channel_name}")
await ctx.reply(f":memo: If you create a voice channel right now, it will be named like this: {channel_name}")
@default_channel_name_subcommands.command("clear", help = "Do not use a special name for your voice channels")
async def clear_user_default_channel_name(self, ctx: commands.Context):
self.channels_config.clear_user_channel_name(ctx.guild, ctx.author)
self.channels_config.save_to_file()
await ctx.send(":white_check_mark: Your voice channels will use the default naming convention")
await ctx.reply(":white_check_mark: Your voice channels will use the default naming convention")
@commands.Cog.listener()
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):