Discord.py特权意图使on_message和命令停止工作

时间:2020-10-01 11:06:26

标签: python discord.py discord.py-rewrite

from discord.ext import commands
from discord.ext import tasks
import random
import typing
from discord import Status
from discord import Activity, ActivityType
from discord import Member
from discord.ext.commands import Bot
from asyncio import sleep


intents = discord.Intents()
intents.members = True
intents.presences = True

print(discord.__version__)
bot = commands.Bot(command_prefix='!', intents =intents)

...
...

@bot.event
async def on_ready():
    print('hiii, We have logged in as {0.user}'.format(bot))
    await bot.change_presence(activity=discord.Game(name="Exploring the archives"))
bot.loop.create_task(status())

@bot.event
async def on_message(message):
    if message.author.id == BOT_ID:
        return

    if message.content.startswith('$hello'):
        await message.channel.send('Hello Dad!')

    await bot.process_commands(message)

@bot.event
async def on_member_update(before,after):
    if before.status  != str(after) :
        print("{}, #{} has gone {} .".format(after.name,after.id,after.status))

@bot.event
async def on_member_remove(member):
    print(f'{member} has left a server.')

@bot.event
async def on_member_join(member):
    print(f'{member} has joined a server.')
    await member.send('Private message')

@bot.command(pass_context=True) 
async def summon(ctx):
       await ctx.send ("I have been summoned by the mighty {}, ".format(ctx.message.author.mention) + " bearer of {}. What is your command?".format(ctx.message.author.id))

你好我试图构建一个不和谐的Bot,但除我无法使on_member_join和on_member_update正常工作(他们似乎并没有注册用户进入或离开服务器的事实,所以我得出结论说,我缺乏一些权限)。经过大量搜索之后,我在discord.py文档中发现了this,并且在我的代码开始添加了意向位之后,on_member_join,on_member_remove和on_member_update起作用了,但是on_message事件和所有命令都没有作用(我在on_message的开头添加了打印内容,但没有任何反应。 经过一些调试后,我发现阻止命令响应的代码似乎是,intents = intents) 。但是,将其删除后,on_member_join,on_member_remove和on_member_update(可以理解)不会触发。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我猜测使用intents = discord.Intents()的所有意图都设置为False

您可以使用intents.messages = Trueintents.all()