我怎样才能在 1 python 脚本中制作一个角色需要的命令和一个非角色需要的命令?

How can i make a role-required command and a non role-required command in 1 python script?

所以我想要一个脚本,如果我在 Discord 服务器中说“$hello”,机器人会回复(我希望每个人都可以使用此命令)。我还想在需要角色或所有者的同一脚本中有一个命令,这是我的关闭命令,我不希望它对其他成员可用:)有人可以帮助我吗?感谢您的阅读!我当前的文字是

import time
import discord
import asyncio
from discord.ext import commands
from discord.ext.commands.core import has_permissions

@client.commands()
@commands.is_owner()
async def shutdown(ctx):
    await ctx.send("Logging Out...")
    client.logout()
    print("Exit")

这就是我现在拥有的

您应该在 @client.command 而不是 @client.event 上进行。这比 on_message

更有效率

在复制和粘贴命令之前,您应该先将它们放在 client

client 上:

client = commands.Bot(command_prefix="$")

关机命令:

@client.command()                     # the decorator
@commands.is_owner()                  # it will check if you (the owner of the bot) runs the bot, 
async def shutdown(ctx):              # your command name
    await ctx.send("Shutting down!")  # send the message
    await client.close()              # shuts down the bot

稍后谢谢我:D