首页 > 解决方案 > 我的服务器票务系统未运行 on_message(message)

问题描述

import discord
client = discord.Client()
@client.event
async def on_ready():
    print('ALERT: {0.user} has connected and is now ready for use.'.format(client))



@client.event
async def on_message(message):
    if message.content.startswith('$request-whitelisting'):
        print("1")
        x = author.has_permissions(administrator)
        print(author)
        if x == False:
            print("2")
            await message.channel.send("OK, I am now alerting the admins who can approve your request.")
            channel = bot.getchannel(784863111579435019)
            idiot = message.author()
            await message.channel.send("Alert: "+idiot+" has requested whitelist.")



client.run('Token')

这就是代码 - 它不起作用,我试图让它只这样做然后运行机器人并且它拒绝,我尝试移动东西,使用 print() 标记问题,但最后,函数不是正在运行。我从 shell 中得到的只是启动消息: ALERT: Bot#NumID has connected and is now ready for use.

标签: pythondiscord.py

解决方案


尝试这样的事情

import discord
intents = Intents.default()
intents.members = True

client = discord.Client(intents = intents)

@client.event
async def on_ready():
    print('ALERT: {0.user} has connected and is now ready for use.'.format(client))



@client.event
async def on_message(message):
    if message.content.startswith('$request-whitelisting'):
        print("1")
        x = author.has_permissions(administrator)
        print(author)
        if x == False:
            print("2")
            await message.channel.send("OK, I am now alerting the admins who can approve your request.")
            channel = bot.getchannel(784863111579435019)
            idiot = message.author()
            await message.channel.send("Alert: "+idiot+" has requested whitelist.")



client.run('Token')

推荐阅读