Событие Discord, из-за которого команды не работают - Discord.py - PullRequest
0 голосов
/ 14 июля 2020

Я новичок в программировании и подумал, что хорошим обучающим проектом будет бот-дискорд для личного сервера, размещенного на heroku. но я натолкнулся на загвоздку, с которой id хотел бы попросить некоторую помощь.

это событие здесь приводит к тому, что все другие команды вообще не работают, и я не могу понять, почему:

import discord
import time
import os
import asyncio
import random

from discord.ext import commands, tasks
from itertools import cycle


client = commands.Bot(command_prefix = '~')

Messages = ['1', '2', '3','4']

@client.command()
async def Load(ctx, extension):
    client.load_extension(f'cogs.{extension}')

@client.command()
async def Unload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')

@client.command()
async def Reload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')
    client.load_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        client.load_extension(f'cogs.{filename[:-3]}')

@client.event
async def on_ready():
    print('Bot is Online')

async def change_status():
    await client.wait_until_ready()
    status = cycle(Messages)

    while not client.is_closed():
        current_status = next(status)
        await client.change_presence(activity=discord.Game(name=current_status))
        await asyncio.sleep(60)
        print ('Status Changed')

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send('Missing required argument')
    if isinstance(error, commands.CommandNotFound):
        await ctx.send('Command does not exist')
    if isinstance(error, commands.CheckFailure):
        await ctx.send('You do not have permission to use this command')

###################################################################################
@client.event
async def on_message(message):
    member = message.author.id
    if message.author.id == XXXXX:
        if "gif" in message.content:
            responses = ['This part works','']
            await message.channel.send(random.choice(responses))
###################################################################################

@client.command()
async def Commands(ctx):
    await ctx.send('shows commands')

@client.command()
async def Test(ctx):
    await ctx.send('command works')

client.loop.create_task(change_status())
client.run(os.environ['token'])

Для контекста у меня есть друг, который любит использовать гифки, чтобы выразить свое мнение, вызывая раздражение всех, поэтому цель - отправить сообщение, когда они это сделают. фрагмент кода, с которым у меня возникла проблема, находится между хешами.

заранее спасибо

1 Ответ

1 голос
/ 14 июля 2020

Добавьте

await client.process_commands(message)

в начало вашей функции on_message. on_message имеет приоритет и всегда отменяет команды, если вы не включите эту строку.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...