Python 如何将意图与cogs一起使用?
你好,我怎样才能把意图和齿轮一起使用呢?我需要去main.py添加意图还是在哪里?我不明白 这是代码本身main.py,我需要命令文件中的命令的意图 请帮帮我,我读了文档,但我没有在cogs中找到意图Python 如何将意图与cogs一起使用?,python,discord.py,bots,Python,Discord.py,Bots,你好,我怎样才能把意图和齿轮一起使用呢?我需要去main.py添加意图还是在哪里?我不明白 这是代码本身main.py,我需要命令文件中的命令的意图 请帮帮我,我读了文档,但我没有在cogs中找到意图 import discord from discord.ext import commands import os TOKEN = '' PREFIX = '!' client = commands.Bot(command_prefix = PREFIX) client.remove_comm
import discord
from discord.ext import commands
import os
TOKEN = ''
PREFIX = '!'
client = commands.Bot(command_prefix = PREFIX)
client.remove_command("help")
intents = discord.Intents.all()
intents.members = True
@client.command()
async def load(ctx, extension):
if ctx.author.id == 375240473184305164:
client.load_extension(f"cogs.{extension}")
await ctx.send("Cogs is loaded...")
else:
await ctx.send("Вы не разработчик бота...")
@client.command()
async def unload(ctx, extension):
if ctx.author.id == 375240473184305164:
client.unload_extension(f"cogs.{extension}")
await ctx.send("Cogs is loaded...")
else:
await ctx.send("Вы не разработчик бота...")
@client.command()
async def reload(ctx, extension):
if ctx.author.id == 375240473184305164:
client.unload_extension(f"cogs.{extension}")
client.load_extension(f"cogs.{extension}")
await ctx.send("Cogs is loaded...")
else:
await ctx.send("Вы не разработчик бота...")
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
client.load_extension(f"cogs.{filename[:-3]}")
client = discord.Client(intents=intents)
client.run(TOKEN)
您定义了两次
client
,去掉最后一个(client=discord.client(intents=intents)
),只需在定义第一个客户端时传递意图即可
intents=discord.intents.all()
client=commands.Bot(command\u prefix=prefix,intents=intents)
您在创建bot对象的地方添加了意图,在您的案例中是客户端
,因此它在主文件中。在您的代码中,您可以删除client=discord.client(intents=intents)
,因为它会使所有代码在它不起任何作用之前都被删除。非常感谢您非常感谢您的成员,如果答案有帮助,请接受