首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >discord.Client是否与用于discord.py的discord.ext.commands兼容?

discord.Client是否与用于discord.py的discord.ext.commands兼容?
EN

Stack Overflow用户
提问于 2020-10-12 10:41:14
回答 1查看 990关注 0票数 0

我有一个非常幼稚的机器人,我想添加一个自动的功能。但是,我的机器人是用discord.ext.commands编写的,要扫描所有消息,我需要discord.Client (我想)。我不确定它们是否可以同时运行,但它们是否兼容?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-13 00:12:19

你不需要discord.Client。如果你已经在使用discord.ext.commands了,你可以这样做。

代码语言:javascript
复制
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_message。必须启用discord.Intents.messages,或者使用intents = discord.Intents.all()启用所有意图

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64311018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档