discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'emd' is not defined
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'emd' is not defined
我正在 Python (Python 39) 中为 Discord 编写一个机器人。我需要一个机器人来管理我在 Discord 中的服务器。
这是机器人本身的代码(没有令牌)
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)
我启动了bot,我写了一个命令来向服务器用户发出mut——一个例子:(.mute @username 30 Test),之后发出了一个特殊的角色“Muted”,这个错误出现在机器人控制台:
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
请帮我解决这个错误,如果你问我用什么,怎么用等等,我会一一解答!!!!
您的问题在最后一行,您输入的是 emd
而不是 emb
。
我正在 Python (Python 39) 中为 Discord 编写一个机器人。我需要一个机器人来管理我在 Discord 中的服务器。 这是机器人本身的代码(没有令牌)
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)
我启动了bot,我写了一个命令来向服务器用户发出mut——一个例子:(.mute @username 30 Test),之后发出了一个特殊的角色“Muted”,这个错误出现在机器人控制台:
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
请帮我解决这个错误,如果你问我用什么,怎么用等等,我会一一解答!!!!
您的问题在最后一行,您输入的是 emd
而不是 emb
。