2024-06-28 11:08:24 发布
网友
我有一个非常幼稚的机器人,我想添加一个automod功能。但是,我的bot是用discord.ext.commands编写的,要扫描所有消息,我需要discord.Client(我想)。我不确定它们是否可以同时运行,但它们是否兼容
你不需要不和,客户。如果您已经在使用discord.ext.commands,则可以按如下操作
import discord from discord.ext import commands intents = discord.Intents.all() bot = commands.Bot(command_prefix=".", intents=intents) @bot.event async def on_ready(): print(f"Bot is ready") await bot.change_presence(status=discord.Status.online, activity=discord.Game(name="example")) @bot.event async def on_message(message): forbidden_word = "word" if forbidden_word in message.content: await message.delete() @bot.command() @commands.has_permissions(kick_members=True) async def kick(ctx, member: discord.Member): await member.kick() await ctx.send(f"Member {member} has been kicked") bot.run("token")
在创建和发送消息时调用on_消息。 必须启用discord.Intents.messages,或者使用Intents=discord.Intents.all()启用所有意图
你不需要不和,客户。如果您已经在使用discord.ext.commands,则可以按如下操作
在创建和发送消息时调用on_消息。 必须启用discord.Intents.messages,或者使用Intents=discord.Intents.all()启用所有意图
相关问题 更多 >
编程相关推荐