首页 > 解决方案 > Discord.py 使用消息时没有输出

问题描述

其目的是限制服务器成员发送垃圾邮件,但在需要时仍会使用。但是,当我尝试使用它时,不会在不和谐上发送任何内容,也没有来自终端端的错误消息。我也没有得到语法错误。我也尝试过在条件中使用or语句而不是语句,但这也不起作用。任何解决方案表示赞赏,在此先感谢。andif

import discord
import random
import datetime
from discord import Embed
from discord.ext import commands

intents = discord.Intents(messages = True, guilds = True, reactions = True, members = True, presences = True)
client = commands.Bot(command_prefix = '*', intents = intents)
    
class PleaseWork(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.last_timeStamp = datetime.datetime.utcfromtimestamp(0)

    @commands.Cog.listener()
    async def on_message(self, message):
        time_difference = (datetime.datetime.utcnow() - self.last_timeStamp).total_seconds()
        if time_difference < 5 and message.author == client.user:
            return

        elif message.content.startswith('yo lebclan'): 
            await message.channel.send('Sup?')
            self.last_timeStamp = datetime.datetime.utcnow()

标签: discorddiscord.pydiscord.py-rewrite

解决方案


你在加载齿轮吗?这可能就是为什么什么都没有显示的原因,这是因为您实际上并没有运行代码,所以它没有告诉您任何信息。

当我遇到同样的问题时,这对我有很大帮助:

https://www.youtube.com/watch?v=vQw8cFfZPx0&list=PLW3GfRiBCHOhfVoiDZpSz8SM_HybXRPzZ&index=7

装载和卸载的第一部分可能是您需要的。


推荐阅读