Python 命令SetPrefix和Json?不和谐
第一: 我想给我的机器人添加更多功能,这样我就可以创建一个新文件夹,在那里我可以尝试新的东西 第二: 我想添加一个命令来设置前缀 第三: 我在bot.py旁边添加了prefix.json文件和start.bat来启动bot 第四: 麻烦 当编写超过1280个like的脚本时,bat和python文件没有加载,它们都关闭了 第五: 剧本Python 命令SetPrefix和Json?不和谐,python,discord,discord.py,Python,Discord,Discord.py,第一: 我想给我的机器人添加更多功能,这样我就可以创建一个新文件夹,在那里我可以尝试新的东西 第二: 我想添加一个命令来设置前缀 第三: 我在bot.py旁边添加了prefix.json文件和start.bat来启动bot 第四: 麻烦 当编写超过1280个like的脚本时,bat和python文件没有加载,它们都关闭了 第五: 剧本 import discord import json from discord.ext import commands def get_prefix(bot,
import discord
import json
from discord.ext import commands
def get_prefix(bot, message):
with open('prefix.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(guild.id)] = '.'
token = 'Private (-:'
bot = commands.Bot(command_prefix='c:', help_command=None)
@bot.event
async def on_ready():
print('Ya estoy')
@bot.event
async def on_guild_join(guild):
with open('prefix.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = '.'
with open('prefix.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@bot.event
async def on_guild_remove(guild):
with open('prefix.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open('prefix.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@bot.command()
async def setprefix(ctx, prefix):
with open('prefix.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open('prefix.json', 'w') as f:
json.dump(prefixes, f, indent=4)
bot.run(token)
第一:有什么问题 第二:您的
get\u prefix
函数需要传递到Bot
代码:
def get_前缀(bot,消息):
将open('prefix.json','r')作为f:
前缀=json.load(f)
返回前缀[str(message.guild.id)]
bot=commands.bot(command\u prefix=get\u prefix,help\u command=None)
第三:你的bat文件有什么问题
第四:我不知道你的球棒在做什么,你在用它做什么。嗨,没有错误!如果我打开python控制台和bat,它只会关闭它们,就好像它不工作一样!我没有很好地定义这个问题,因为没有错误代码,只有控制台在打开几秒钟后才关闭!另一件事是,与我的机器人的官方脚本没有发生,它的工作相当好!我使用bat是因为我的官方机器人的脚本没有正确打开,但bat正确执行所有操作!我已经试过做你做的第二件事了,但也没用!我刚刚意识到你正在覆盖公会的前缀,但没有返回任何前缀
返回前缀[str(guild.id)]='.
应该是返回前缀[str(guild.id)]
您可能还应该在某处添加默认前缀