【发布时间】:2021-12-13 05:31:10
【问题描述】:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "", intents = discord.Intents.all())
class music(commands.Cog):
def __init__(self, client):
self.client = client
@client.command()
async def join(self, ctx):
if ctx.author.voice is None:
await ctx.send("You are not in a voice channel")
@client.command() 和 @commands.command() 都有效,实际上有什么区别?
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "", intents = discord.Intents.all())
class music(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def join(self, ctx):
if ctx.author.voice is None:
await ctx.send("You are not in a voice channel")
【问题讨论】:
-
commands.command() 在扩展中使用,因为客户端没有在那里定义。我不相信有任何区别。
-
加上 Taku 所说的,
commands.command()用于 cogs。
标签: python discord discord.py