Discord Bot不响应命令

时间:2018-12-30 18:38:48

标签: python-3.x discord.py

过去一个月,我一直在开发一个discord机器人,我一直在使用on_message侦听器执行命令,据许多在线人士说,这并不是很理想,所以我决定将其下一步正确完成操作后,我查看了文档并提出了以下基本代码:

import discord #import all the necessary modules
from discord import Game
from discord.ext import commands

client = discord.Client() #define discord client
bot = commands.Bot(command_prefix='!') #define command decorator

@bot.command(pass_context=True) #define the first command and set prefix to '!'
async def testt(ctx):
    await ctx.send('Hello!!')

@client.event #print that the bot is ready to make sure that it actually logged on
async def on_ready():
    print('Logged in as:')
    print(client.user.name)
    await client.change_presence(game=Game(name="in rain ¬ !jhelp"))

client.run(TOKEN) #run the client using using my bot's token

在经历将所有命令实现为这种新的工作方式的痛苦之前,我想对其进行测试,因此我知道它确实可以工作,可悲的是,没有,我经历了很多帖子和文档再次出现,但我无法发现我做错了什么,该僵尸程序可以正确地登录到正确的用户,而且我似乎无法弄清并理解问题所在,很可能又会丢失一些明显的东西

谁能帮忙,那太好了,谢谢!

1 个答案:

答案 0 :(得分:1)

client = discord.Client()就是说您创建了一个不和谐的客户端,该客户端当然会在线(如果甚至不在线,请告诉我),并且您使用bot = commands.Bot(command_prefix='!')做出了不和谐的机器人。 discord bot不会运行,只有Discord客户端会运行,因为您只使用client.run(TOKEN)运行了该客户端。因此,可以快速预览一下您的代码应该是什么,并希望它可以工作:

import discord #import all the necessary modules
from discord import Game
from discord.ext import commands

bot = commands.Bot(command_prefix='!') #define command decorator

@bot.command(pass_context=True) #define the first command and set prefix to '!'
async def testt(ctx):
    await ctx.send('Hello!!')

@bot.event #print that the bot is ready to make sure that it actually logged on
async def on_ready():
    print('Logged in as:')
    print(bot.user.name)
    await bot.change_presence(game=Game(name="in rain ¬ !jhelp"))

bot.run(TOKEN) #run the client using using my bot's token
相关问题