为什么此程序无法在不使discord.py错误的情况下检索消息

时间:2019-06-08 15:18:53

标签: python discord.py-rewrite

我正在尝试检查不一致发送的消息是否包含特定内容(最终目标是反宣誓的机器人),并且每当发送消息时都会收到此错误。

Bot is ready. Ignoring exception in on_message Traceback (most recent call last):   File "C:\Users\Coran\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 251, in _run_event
    await coro(*args, **kwargs)   File "C:\Users\Coran\OneDrive\Desktop\Bully bot\bullybot.py", line 32, in on_message
    if message.content.includes("E"): NameError: name 'message' is not defined

程序

import discord 
import random 
from discord.ext import commands

client = commands.Bot(command_prefix = ".")

@client.event 
async def on_ready():
    print ("Bot is ready.")

@client.command() 
async def ping(ctx):
    await ctx.send(f'Pong! {client.latency * 1000}ms')

@client.command(aliases=['8ball']) 
async def _8ball(ctx, *, question):
    responses = ['It is certain.',
                 'It is decidedly so.',
                 'Yes - definitely.',
                 'Reply hazy, try again.',
                 "Don't count on it.",
                 'Outlook not so good.',
                 'Very doubtful.']
    await ctx.send(f'Question: {question}\nAnswer: {random.choice(responses)}')

@client.event 
async def on_message(ctx):
    print ("message sent.")
@client.event 
async def on_message(ctx):
if message.content.includes("E"):
    print ("Yay")

当发送包含E的消息时,该代码应在控制台中打印,如果该消息不包含E,则不打印任何内容。 但是无论发送什么,我都只会收到此错误。

0 个答案:

没有答案