【问题标题】:Why am I getting this error The command on_message is already an existing command or alias为什么我收到此错误命令 on_message 已经是现有命令或别名
【发布时间】:2021-01-24 15:46:39
【问题描述】:

我在处理这段代码时遇到了问题(抱歉它太长了):

import discord, random, asyncio, datetime, time, os
from discord.utils import get
from discord.ext import commands
from discord.ext.commands import bot
import json 

bot = commands.Bot(command_prefix="aag!", case_insensitive=True)

@bot.event
async def on_ready():
  await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="dick pills"))
  print("gay")

@bot.event
async def on_guild_join(guild):
  for channel in guild.text_channels:
    if channel.permissions_for(guild.me).send_messages:
      await channel.send('**Hello I am AAG Bot! Here are some of my features:                          **__AAG Ultimate Team:__** _To get started with AAG UT start with the command_ `aag!UT`                           **__Signing Method:__** _Give all credit to @Doggy for making this part possible!_                           **__Economy Commands for UT:__** _to start using economy use command_ `aag!signup`')
      break

@bot.check
async def __before_invoke(ctx):
    if not ctx.message.author.bot:
        return True

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':ARI1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Arizona Cardinals**")
      await bot.add_roles(member, role="@Arizona Cardinals")
      await bot.say(f"**{member.mention} Signed to Arizona Cardinals**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':ATL1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Atlanta Falcons**")
      await bot.add_roles(member, role="@Atlanta Falcons")
      await bot.say(f"**{member.mention} Signed to Atlanta Falcons**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':BAL1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Baltimore Ravens**")
      await bot.add_roles(member, role="@Baltimore Ravens")
      await bot.say(f"**{member.mention} Signed to Baltimore Ravens**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':BUF1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Buffalo Bills**")
      await bot.add_roles(member, role="@Buffalo Bills")
      await bot.say(f"**{member.mention} Signed to Buffalo Bills**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':CAR1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Carolina Panthers**")
      await bot.add_roles(member, role="@Carolina Panthers")
      await bot.say(f"**{member.mention} Signed to Carolina Panthers**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':CIN1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Cincinnati Bengals**")
      await bot.add_roles(member, role="@Cincinnati Bengals")
      await bot.say(f"**{member.mention} Signed to Cincinnati Bengals**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':CHI1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Chicago Bears**")
      await bot.add_roles(member, role="@Chicago Bears")
      await bot.say(f"**{member.mention} Signed to Chicago Bears**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':CLE1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Cleveland Browns**")
      await bot.add_roles(member, role="@Cleveland Browns")
      await bot.say(f"**{member.mention} Signed to Cleveland Browns**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':DAL1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Dallas Cowboys**")
      await bot.add_roles(member, role="@Dallas Cowboys")
      await bot.say(f"**{member.mention} Signed to Dallas Cowboys**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':DEN1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Denver Broncos**")
      await bot.add_roles(member, role="@Denver Broncos")
      await bot.say(f"**{member.mention} Signed to Denver Broncos**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':DET1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Detroit Lions**")
      await bot.add_roles(member, role="@Detroit Lions")
      await bot.say(f"**{member.mention} Signed to Detroit Lions**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':GB1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Green Bay Packers**")
      await bot.add_roles(member, role="@Green Bay Packers")
      await bot.say(f"**{member.mention} Signed to Green Bay Packers**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':HOU1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Houston Texans**")
      await bot.add_roles(member, role="@Houston Texans")
      await bot.say(f"**{member.mention} Signed to Houston Texans**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':IND1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Indianapolis Colts**")
      await bot.add_roles(member, role="@Indianapolis Colts")
      await bot.say(f"**{member.mention} Signed to Indianapolis Colts**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':KC1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Kansas City Chiefs**")
      await bot.add_roles(member, role="@Kansas City Chiefs")
      await bot.say(f"**{member.mention} Signed to Kansas City Chiefs**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':LAC1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Los Angeles Chargers**")
      await bot.add_roles(member, role="@Los Angeles Chargers")
      await bot.say(f"**{member.mention} Signed to Los Angeles Chargers**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':LAR1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Los Angeles Rams**")
      await bot.add_roles(member, role="@Los Angeles Rams")
      await bot.say(f"**{member.mention} Signed to Los Angeles Rams**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':JAX1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Jacksonville Jaguars**")
      await bot.add_roles(member, role="@Jacksonville Jaguars")
      await bot.say(f"**{member.mention} Signed to Jacksonville Jaguars**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':MIA1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Miami Dolphins**")
      await bot.add_roles(member, role="@Miami Dolphins")
      await bot.say(f"**{member.mention} Signed to Miami Dolphins**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':MIN1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Minnesota Vikings**")
      await bot.add_roles(member, role="@Minnesota Vikings")
      await bot.say(f"**{member.mention} Signed to Minnesota Vikings**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':NE1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to New England Patriots**")
      await bot.add_roles(member, role="@New England Patriots")
      await bot.say(f"**{member.mention} Signed to New England Patriots**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':NO1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to New Orleans Saints**")
      await bot.add_roles(member, role="@New Orleans Saints")
      await bot.say(f"**{member.mention} Signed to New Orleans Saints**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':NYG1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to New York Giants**")
      await bot.add_roles(member, role="@New York Giants")
      await bot.say(f"**{member.mention} Signed to New York Giants**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':NYJ1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to New York Jets**")
      await bot.add_roles(member, role="@New York Jets")
      await bot.say(f"**{member.mention} Signed to New York Jets**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':LV1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Las Vegas Raiders**")
      await bot.add_roles(member, role="@Las Vegas Raiders")
      await bot.say(f"**{member.mention} Signed to Las Vegas Raiders**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':PHI1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Philadelphia Eagles**")
      await bot.add_roles(member, role="@Philadelphia Eagles")
      await bot.say(f"**{member.mention} Signed to Philadelphia Eagles**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':SF1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to San Francisco 49ers**")
      await bot.add_roles(member, role="@San Francisco 49ers")
      await bot.say(f"**{member.mention} Signed to San Francisco 49ers**")

@bot.command()
async def on_message(message, member: discord.Member, *, role: discord.Role):
  if bot.user.id != message.author.id:
    if f':SEA1: sign {member.mention}' in message.content:
      await bot.say(f"**Signing {member.mention} to Seattle Seahawks**")
      await bot.add_roles(member, role="@Seattle Seahawks")
      await bot.say(f"**{member.mention} Signed to Seattle Seahawks**")

#keep_alive.keep_alive()
token = os.environ.get("TOKEN")
bot.run(token, bot=True)

不要说令牌不存在我知道它不存在。

但随后我收到此错误消息:

Traceback(最近一次调用最后一次): 文件“main.py”,第 137 行,在 async def on_message(消息,成员:discord.Member,*,角色:discord.Role): 文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 1246 行,在装饰器中 self.add_command(结果) 文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 1138 行,在 add_command 引发 CommandRegistrationError(command.name) discord.ext.commands.errors.CommandRegistrationError:命令 on_message 已经是现有命令或别名。

我不知道这意味着什么,请比我更有知识的人指导我完成这个 LOL。

【问题讨论】:

  • 我认为不同的功能需要不同的名称
  • 所以你的意思是async def on_message(message, member: discord.Member, *, role: discord.Role)在括号内使用不同的函数?
  • 尝试将其称为 on_message1、on_message2 等等:async def on_message1(message, member: discord.Member, *, role: discord.Role)
  • 好的,谢谢,我试试看!
  • 您使用的是 repl.it 版本的 discord.py 吗?重写中没有bot.say

标签: python discord discord.py


【解决方案1】:

块引用 尝试将其称为 on_message1 on_message2 等等:async def on_message1(message, member: discord.member, *, role: discord.Role) - jacob galam

感谢 jacob,代码现在可以工作了!

【讨论】:

    猜你喜欢
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    • 2021-08-03
    • 2022-10-01
    • 1970-01-01
    相关资源
    最近更新 更多