Discord.py on_message: 当我输入消息时没有任何反应
Discord.py on_message: nothin happens when i type the message
import discord
from discord.ext import commands
TOKEN = 'XXXXX'
prefix = "!"
client = discord.Client()
@client.event
async def on_message(message):
if message.content == prefix + "hey":
await client.reply("hello there")
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
在第一个@client.event 中,当我使用前缀+“嘿”给出的命令时,没有任何反应。它没有给出所需的答复
AttributeError: 'Client' 对象没有属性 'reply'
这就是我得到的错误
您需要使用 message.reply
而不是 client.reply
。
请注意,最好使用特殊的 discord.py 装饰器创建命令:
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
@bot.command()
async def hey(ctx):
ctx.reply("Hello there!")
bot.run("TOKEN")
使用 @client.listen()
,我以前遇到过,listen()
有效
import discord
from discord.ext import commands
TOKEN = 'XXXXX'
prefix = "!"
client = discord.Client()
@client.event
async def on_message(message):
if message.content == prefix + "hey":
await client.reply("hello there")
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
在第一个@client.event 中,当我使用前缀+“嘿”给出的命令时,没有任何反应。它没有给出所需的答复
AttributeError: 'Client' 对象没有属性 'reply'
这就是我得到的错误
您需要使用 message.reply
而不是 client.reply
。
请注意,最好使用特殊的 discord.py 装饰器创建命令:
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
@bot.command()
async def hey(ctx):
ctx.reply("Hello there!")
bot.run("TOKEN")
使用 @client.listen()
,我以前遇到过,listen()
有效