如何制作自定义状态命令Discord.py

问题描述 投票:0回答:1

我尝试制作一个自定义的不和谐状态命令,它正在工作,但打印出来并将机器人状态设置为('args',),其中args是用户输入的内容

这是该命令的当前代码行:

@bot.event
async def on_ready():
    print("The Bot is now Online")
    print("----------------------------------------")
    await bot.change_presence(status=discord.Status.online, activity= discord.Activity(type = discord.ActivityType.listening, name = 'To the server'))


@bot.command()
async def Status(ctx, *args):
        await bot.change_presence(status=discord.Status.online, activity= discord.Activity(type = discord.ActivityType.listening, name = f'{args}'))  
        await ctx.send(args) 
        print(args)

这会在控制台中打印出来,发送到不和谐频道并将机器人状态设置为('args',),因此如果我要执行命令.Status Hey,它会将其设置为('Hey',)

python discord discord.py
1个回答
0
投票

这是一个简单的错字。当您真正需要

*args
时,您可以放置
*, args
。 像这样的东西。

from discord.ext.commands import Bot
import discord

bot = Bot(command_prefix = '!', intents=discord.Intents.all())

@bot.event
async def on_ready():
    print("The Bot is now Online")
    print("----------------------------------------")
    await bot.change_presence(status=discord.Status.online, activity= discord.Activity(type = discord.ActivityType.listening, name = 'To the server'))


@bot.command()
async def Status(ctx, *, args):
        await bot.change_presence(status=discord.Status.online, activity= discord.Activity(type = discord.ActivityType.listening, name = f'{args}'))  
        await ctx.send(args) 
        print(args)

bot.run("TOKEN")
© www.soinside.com 2019 - 2024. All rights reserved.