如何在discord.py中进行更改前缀命令

时间:2020-10-28 22:15:33

标签: discord.py

我想输入一个更改前缀命令。这是原始代码,但是在您看之前,我到处都是,但仍然找不到所有内容。

def get_prefix(bot, 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)








@bot.event
async def on_guild_join(guild):


    with open("prefixes.json", "r") as f:
        prefixes = json.load(f)

    prefixes[str(guild.id)] = "!"

    with open("prefixes.json", "w") as f:
        json.dump(prefixes,f)


@bot.command()
@commands.has_guild_permissions(administrator=True)
async def changeprefix(ctx, prefix):

    with open("prefixes.json", "r") as f:
        prefixes = json.load(f)

    prefixes[str(guild.id)] = prefix

    with open("prefixes.json", "w") as f:
        json.dump((prefixes,f))


@bot.event
async def on_message(msg):

    if msg.mentions[0] == bot.user:
        with open("prefixes.json", "r") as f:
         prefixes = json.load(f)

        pre = prefixes[str(msg.guild.id)]

        await msg.channel.send(f"My prefix for this server is {pre}")

    await bot.process_commands(msg)```


but then i kept on getting this error 
https://hastebin.com/bokezijece.rust

Can someone please help me i have looked at online tutorials and still cant get it to work and i even ask my freind that already has it but he wont help me because he is stubborn. I have asked every where and either non of the solutions work or they just straight up dont help me. and now stackoverflow is starting to anoy me as it is still saying my stuff is more code than detail aaaa.

0 个答案:

没有答案