是否可以一次具有多个前缀? 例: @discordbot帮助 ; help(自定义前缀) 和dms \救命 (我有一个工作的前缀转换器和加载器)
如果有的话,请给我看个例子或修复我的破损代码
代码:
import discord
import json
from discord import Embed
from discord.ext import commands
from discord.ext.commands import when_mentioned
def get_prefix(client, message):
guild = message.guild
if guild:
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(int(message.guild.id))]
elif not guild:
return ','
else:
return when_mentioned(client, message)
client = commands.client(command_prefix=get_prefix)
@client.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(int(guild.id))] = '//'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(int(guild.id)))
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command()
async def prefix(ctx, *, prefix):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(int(ctx.guild.id))] = prefix
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command()
async def ping(ctx):
await ctx.send('pong')
@client.event
async def on_ready():
print('ready')
client.run(token)
如果没有,请给我举个例子,谢谢
答案 0 :(得分:0)
您可以像这样
prefixes = ";", "/"
bot = commands.Bot(command_prefix=prefixes)