import random, string
import re
from random import choice
import time
import json
import requests
from itertools import cycle
import random
import os
def get_prefix(client, message): ##first we define get_prefix
with open('/Users/Користувач/Desktop/Kiris/prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
return prefixes[str(message.guild.id)] #recieve the prefix for the guild id given
return prefixes[str(message.guild.id)]
client = commands.Bot(
command_prefix= (get_prefix),
)
@client.event
async def on_guild_join(guild): #when the bot joins the guild
with open('/Users/Користувач/Desktop/Kiris/prefixes.json', 'r') as f: #read the prefix.json file
prefixes = json.load(f) #load the json file
prefixes[str(guild.id)] = 'bl!'#default prefix
with open('/Users/Користувач/Desktop/Kiris/prefixes.json', 'w') as f: #write in the prefix.json "message.guild.id": "bl!"
json.dump(prefixes, f, indent=4) #the indent is to make everything look a bit neater
@client.event
async def on_guild_remove(guild): #when the bot is removed from the guild
with open('/Users/Користувач/Desktop/Kiris/prefixes.json', 'r') as f: #read the file
prefixes = json.load(f)
prefixes.pop(str(guild.id)) #find the guild.id that bot was removed from
with open('/Users/Користувач/Desktop/Kiris/prefixes.json', 'w') as f: #deletes the guild.id as well as its prefix
json.dump(prefixes, f, indent=4)
@client.command(pass_context=True)
async def changeprefix(ctx, prefix = None): #command: bl!changeprefix ...
with open('/Users/Користувач/Desktop/Kiris/prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open('/Users/Користувач/Desktop/Kiris/prefixes.json', 'w') as f: #writes the new prefix into the .json
json.dump(prefixes, f, indent=4)
await ctx.send(f'Prefix changed to: {prefix}') #confirms the prefix it's been changed to
#next step completely optional: changes bot nickname to also have prefix in the nickname
name=f'{prefix}BotBot'
вот ошибки ис консоли