我正在用python(python39)为discord编写一个bot。我需要一个机器人来缓和我的服务器不和谐。下面是bot本身的代码(不带令牌)
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=802869420086919169)
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),然后发出一个特殊角色“mute”,此错误出现在bot控制台中:
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
请帮我修正这个错误,如果你问我用什么,怎么用等等,我会回答你所有的问题!!!!!
1条答案
按热度按时间xnifntxz1#
你的问题是在最后一行,你键入
emd
而不是emb
.