Reputation: 162
I have my bot to have a specific prefix for each server. I want it to be able to say what prefix it's using for that server by using {prefix}help. Below is my code for the prefixes.
def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
bot = commands.Bot(command_prefix=(get_prefix), intents=discord.Intents.all())
bot.remove_command("help")
Here is to change the prefix.
@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def changeprefix(ctx, prefix):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
await ctx.send(f'Prefix changed to: {prefix}')
This is the code i have to show what current prefix the server is using. This is only part of my help command.
embed.add_field(name="Current Prefix", value=f'The current prefix for this server is {get_prefix}', inline=False)
embed.set_footer(text="I'm strongly recommened for FAMILY FRIENDLY servers!")
await ctx.send(embed=embed)
I tried this code above and got this,
Im asking how can i get the bot to say, "The prefix for this server is {prefix}
Upvotes: 0
Views: 445
Reputation: 1318
Your code is outputting a function object because that is what you asked it for. This is a very common mistake in Python, and is a trap that we all fall for every once in a while. You should be able to solve this problem by changing your value to get_prefix(client, ctx.message)
.
Upvotes: 1