Search code examples
pythonpython-3.9

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'emd' is not defined


I'm writing a bot for Discord in Python (Python 39). I need a bot to moderate my server in Discord. Here is the code of the bot itself (without the token)

import discord
from discord.ext import commands
from discord.ext.commands import bot

Bot = commands.Bot(command_prefix=".")

@Bot.command()
async def say(ctx,arg): #Бот напишет что ты ему напишешь
    await ctx.send(arg)

@Bot.command()
async def info(ctx,member:discord.Member): #Информация о пользователе
    emb = discord.Embed(title='Информация о пользователе',color=0xff0000) #title-слова жирным тектом, color-цвет полоски слева от текста.
    emb.add_field(name="Когда присоединился:",value=member.joined_at,inline=False)
    emb.add_field(name='Имя:',value=member.display_name,inline=False)
    emb.add_field(name='Айди:',value=member.id,inline=False)
    emb.add_field(name="Аккаунт был создан",value=member.created_at.strftime("%a,%#d %B %Y, %I:%M %p UTC"),inline=False)
    emb.set_thumbnail(url=member.avatar_url)
    emb.set_footer(text=f"Вызвано: {ctx.message.author}",icon_url=ctx.message.author.avatar_url)
    emb.set_author(name=ctx.message.author,icon_url=ctx.message.author.avatar_url)
    await ctx.send(embed = emb)

@Bot.command()
@commands.has_permissions(view_audit_log=True)
async def mute(ctx,member:discord.Member,time:int,reason):
    muterole = discord.utils.get(ctx.guild.roles,id=%%%%%%%%%%%%%%%%%%%%%%%)
    emb = discord.Embed(title="Мут",color=0xff0000)
    emb.add_field(name='Модератор',value=ctx.message.author.mention,inline=False)
    emb.add_field(name='Нарушитель',value=member.mention,inline=False)
    emb.add_field(name='Причина',value=reason,inline=False)
    emb.add_field(name='Время',value=time,inline=False)
    await member.add_roles(muterole)
    await ctx.send(embed = emd)

I start the bot, I write a command to issue a mut to the server user-an example:(. mute @username 30 Test), after which a special role "Muted" is issued and this error appears in the bot console:


Ignoring exception in command mute:
Traceback (most recent call last):
  File "C:\Users\Макс\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:\Users\Макс\DRACULA-rms\bot.py", line 33, in mute
    await ctx.send(embed = emd)
NameError: name 'emd' is not defined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Макс\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Макс\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Макс\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'emd' is not defined

Please help me fix this error, if you ask me what I use, how and so on, I will answer all your questions!!!!!


Solution

  • Your issue is on the final line, you typed emd instead of emb.