Home > Software engineering >  How can i get guild name using discord.py
How can i get guild name using discord.py

Time:01-06

@client.command()
async def kick(ctx, member : discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.send(f"{member.name} has been kicked by {ctx.author.name}\nReason: {reason}")
    await ctx.send(member, f"You have been kicked from {member.guild.name} reason: {reason}"

This is the return

from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: Messageable.send() takes from 1 to 2 positional arguments but 3 were given

CodePudding user response:

The error message says that ctx.send() takes 1 or 2 positional arguments, and you've provided 3. In python, methods implicitly pass self, so this line:

await ctx.send(member, f"You have been kicked from {member.guild.name} reason: {reason}"

Actually is passing three arguments, because there's an implicit self at the start. Since ctx.send() needs either 0 or 1 parameters of your own, what you probably actually want is this:

await ctx.send(f"{member}, you have been kicked from {member.guild.name} reason: {reason}"
  •  Tags:  
  • Related