Q: How to change channel name where the channel will be the mentioned channel or ctx.channel depending on if I mention a channel or not The title is a bit confusing, but I want to make a command where it'll allow the user to change a channels name. Now i want it to change ctx.channel's name if no channel is mentioned in the command, and the mentioned channel if one is mentioned. Here is what I tried, but it doesn't work:
  @_channel.command(name="rename",
                    aliases=["re"],
                    brief="Renames channel.",
                    help="Renames the current channel or mentioned channel if argument passed.")
  async def _rename(self, ctx, channel, *, newname=None):
      if not newname:
          newname = channel
          channel = ctx.channel
          current_name = ctx.channel.name
          await ctx.channel.edit(name = newname)
          await ctx.send(f"Changed channel name from **{current_name}** to **{ctx.channel.name}**.")

      elif newname != None:
          current_name = ctx.channel.name
          await ctx.channel.edit(name = newname)
          await ctx.send(f"Changed channel name from **{current_name}** to **{ctx.channel.name}**.")

For example if i do the command >ch rename general i want it to rename the ctx.channel's name to 'general' but if I mention a channel and do >ch rename #bot general i want it to change the mentioned 'bot' channel's name to 'general'

A: You can use discord converters. This allows you to ask discord.py to try to convert arguments for you. Optional[discord.TextChannel] means try to convert one argument to discord.TextChannel and if it fails set value to None.
from typing import Optional

@commands.command(name='rename')
async def _rename(ctx, channel: Optional[discord.TextChannel] = None, *, new_name = None):
    if channel is None:
        channel = ctx.channel
    await ctx.send(f'Change {channel} to {new_name}')

You might want to throw an error if new_name is None.

A: Here's the final command, tweaked to fit my needs thanks to @Nevus' help!
  @_channel.command(name="rename",
                    aliases=["re"],
                    brief="Renames channel.",
                    help="Renames the current channel or mentioned channel if argument passed.")

  async def _rename(self, ctx, channel: Optional[discord.TextChannel] = None, *, newname):
      if channel is None:
          channel = ctx.channel

      current_name = channel.name
      await channel.edit(name = newname)
      await ctx.send(f"Changed {channel.mention}'s name from **{current_name}** to **{channel.name}**.")

