我对编程还很陌生,并认为一个好的学习项目将是所有托管在heroku上的个人服务器的不协调机器人。但我遇到了一个想帮忙的障碍。
此事件导致所有其他命令根本不起作用,我无法完全理解原因:
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'])
对于上下文,我有一个喜欢使用gif的朋友,将他们的意见传达给每个人的烦恼,因此,目的是在他们这样做时发送消息。我有问题的那段代码是在哈希之间。
先谢谢您
答案 0 :(得分:1)
添加
await client.process_commands(message)
到on_message函数的开头。 on_message具有优先权,如果您不包括此行,它将始终取消命令。