如何根据变量更改discord命令

时间:2018-04-30 06:41:05

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

用户可以在设置中更改命令。这把它放在一个变量中,但我需要将该变量作为一个机器人命令。

import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import chalk
import requests
import random

command = "test"

@bot.command(pass_context=True)
@commands.cooldown(1.0, 30.0, commands.BucketType.default)
async def command(ctx):
    await bot.say("Test!")
    print ("Test posted")

1 个答案:

答案 0 :(得分:1)

您可以通过修改name

中的@bot.command(...)属性,将变量用作命令名称
from discord.ext import commands

c_name = "test"
bot = commands.Bot("@")

@bot.command(pass_context=True, name=c_name)
async def _(ctx):
    await bot.say("Test!")
    print ("Test posted")


bot.run("token")

在不和谐中,如果您输入:

You: @test
Bot: Test!