不和谐机器人不响应命令

时间:2021-03-20 08:30:11

标签: python-3.x command discord.py

我正在尝试制作一个不和谐的机器人,我正在尝试为它创建一个命令。但是机器人不响应命令。代码如下:

clientSession.serverSession.txnNumber

任何帮助???

1 个答案:

答案 0 :(得分:-1)

您需要一个 on_message 事件。

import discord
from discord.ext import commands
import logging

logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='err.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)

bot = commands.Bot(command_prefix='!')

token = 'BOT TOKEN'
GUILD = 'My test server'
prefix = bot.command_prefix

@bot.event
async def on_ready():
    guild = discord.utils.get(bot.guilds, name=GUILD)
    print(
        f'{bot.user} is connected to the following server:\n'
        f'{guild.name}(id: {guild.id})'
    )
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name="minecraft"))

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    await bot.process_commands(message)

#here is the command where the bot is not responding to
@bot.command() # you don't need name to be say, since it's already say in the command definition
async def say(ctx, arg):
    await ctx.send(arg)

bot.run(token)