【问题标题】:Custom Prefix Discord.py自定义前缀 Discord.py
【发布时间】:2021-03-31 02:40:16
【问题描述】:

我正在尝试找到一种方法来创建一个命令,该命令可以为我的机器人的不同服务器设置自定义前缀。如果有任何帮助,我也在使用 Cogs...

主文件:

import discord
import os
from discord.ext import commands

client = commands.Bot(command_prefix = '/')

@client.command()
async def load(ctx, extension):
    client.load_extension(f'cogs.{extension}')

@client.command()
async def unload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
      client.load_extension(f'cogs.{filename[:-3]}')


client.run('My Token')

【问题讨论】:

标签: python python-3.x bots discord.py


【解决方案1】:
async def get_prefix(bot, message):
    guild = message.guild
    # you can do something here with the guild obj, open a file and return something different per guild
    default_prefix, custom_prefix = '.', '>'
    return [default_prefix, custom_prefix]

client = commands.Bot(command_prefix=get_prefix)

每次处理命令时都会调用该函数。

【讨论】:

    猜你喜欢
    • 2021-04-04
    • 2021-11-01
    • 2020-12-31
    • 2021-03-30
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 2014-07-08
    • 2019-12-19
    相关资源
    最近更新 更多