【问题标题】:How do change a discord command based on a variable如何根据变量更改不和谐命令
【发布时间】:2018-04-30 06:41:05
【问题描述】:

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

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")

【问题讨论】:

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


    【解决方案1】:

    可以通过修改@bot.command(...)中的name属性来使用变量作为命令名

    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!
    

    【讨论】:

      猜你喜欢
      • 2021-10-02
      • 2021-10-30
      • 1970-01-01
      • 2020-03-05
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 2020-07-13
      • 2020-09-26
      相关资源
      最近更新 更多