开发者问题收集

discord 上没有回应

2021-12-15
193

嘿,所以当我输入 $opgg 或 $ftgopgg 时,它不会出现以下任何内容

@bot.event
async def on_message(message):
  if message.content('$opgg'): 
    response = 'Spend me the names'
    await message.channel.send(response)
    def check(m):
      return m.author.id == message.author.id


    
    opgg = await bot.wait_for('message')
    await message.channel.send(f'https://oce.op.gg/multi/query={opgg.content.replace(" ", "%20")}')
    print("done")

@bot.event
async def on_message(message):
  if message.content == '$ftgopgg': 
    teamopgg = "https://oce.op.gg/multi/query=Disco Inferno, spranze, killogee, blank76, reeks"
    
    
    await message.send(teamopgg.replace(" ", "%20"))
    
    print("Tdone")

它在一个小时前就可以工作了,但我无法使用这两个命令,我不知道我是否得到了代码工作或者是否存在错误

3个回答

您有 2 个 on_message 事件,但 discord.py 仅支持一个。

如果您尝试为您的机器人创建命令,我建议使用 @client.command() 装饰器,而不是监听 on_message 事件。

类似于:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="$", intents=discord.Intents.all())

@bot.command()
async def opgg(ctx):
    response = "Spend me the names"
    await message.channel.send(response)
    def check(m):
      return m.author.id == message.author.id

@bot.command()
async def ftgopgg(ctx):
    teamopgg = "https://oce.op.gg/multi/query=Disco Inferno, spranze, killogee, blank76, reeks"
    await message.send(teamopgg.replace(" ", "%20"))
    print("Tdone")

bot.run("TOKEN")
Ratery
2021-12-15

如果您想同时使用 bot.command() on_message 事件,您可以使用:

@bot.listen()
async def on_message(message):

代替:

@bot.event
async def on_message(message):
šeki
2021-12-15

简单修复,我所要做的就是删除下面的 @bot.eventasync def on_message(message)

新代码:

@bot.event
async def on_message(message):
  if message.content('$opgg'): 
    response = 'Spend me the names'
    await message.channel.send(response)
    def check(m):
      return m.author.id == message.author.id


    
    opgg = await bot.wait_for('message')
    await message.channel.send(f'https://oce.op.gg/multi/query={opgg.content.replace(" ", "%20")}')
    print("done")

 if message.content == '$ftgopgg': 
    teamopgg = "https://oce.op.gg/multi/query=Disco Inferno, spranze, killogee, blank76, reeks"
    
    
    await message.send(teamopgg.replace(" ", "%20"))
    
    print("Tdone")
Killogee
2021-12-16