我已经尝试了几个小时,以获得这个问题的修复,从寻找和数以百计的其他溢出帖子到文档论坛等,我不能搞清楚这一点,我试图发送一个嵌入作为PM到用户指定在我的函数一切工作,除了它应该发送私人消息的一部分,请帮助
误差
bot has no attribute send_message
bot has no attribute send
代码波纹管
@bot.command()
@commands.has_role("mod")
async def mute(ctx, user: discord.Member, duration_arg: str = "30", unit: str = "s", reason: str = "null"):
await ctx.channel.purge(limit=1)
moderator = ctx.message.author
#await ctx.invoke(bot.get_command('ask.{user}'.format(use), length=duration_arg))
channel = bot.get_channel(1060922421491793981)
duration = int(duration_arg)
role = discord.utils.get(ctx.message.guild.roles, id=1060693595964842165)
units = " Null"
if unit == "s":
units = " seconds"
elif unit == "m":
units = " minutes"
else:
return
length = f"{duration_arg}{units}"
if unit == "s":
wait = 1 * duration
await asyncio.sleep(wait)
elif unit == "m":
wait = 60 * duration
await ctx.send(f":mute: Muted {user} for {duration}{units}", delete_after=wait)
await user.add_roles(role)
#button embed---------
view = Confirm()
#await ctx.send('you have been **Muted**', view=view, delete_after=45)
embedVar = discord.Embed(title="You have been Muted",description=f"this message will expire in **{duration_arg}** {units}",color=0x0ff0000)
embedVar.add_field(name="Temporary Suspension for:", value=f"{user.mention}",inline=False)
embedVar.add_field(name="Durration:", value=f"{length}", inline=False)
embedVar.add_field(name="Reason:", value=f"{reason}", inline=False)
embedVar.add_field(name="Moderator:", value=f"{moderator.display_name}", inline=False)
embedVar.add_field(name="Summary",value=f"you can confirm this in the next {duration} {units}\n\n **if you believe this is in error appeal it and a moderator will review your temporary suspension**",inline=False)
embedVar.set_footer(text='Booty Police | mute management',icon_url="http://canvaswrite.com/PI/pybot/attachments/server-icon-full.png")
await bot.send_message(user.id, embed=embedVar, view=view, delete_after=wait)
# Wait for the View to stop listening for input...
await view.wait()
if view.value is None:
print('Timed out...')
elif view.value:
print('appealing...')
elif view.value is appeal:
print('Appealing...')
channel.send("this is a test to appeal...")
else:
print('Cancelled...')
#end buttons----------
if unit == "s":
wait = 1 * duration
await asyncio.sleep(wait)
elif unit == "m":
wait = 60 * duration
await asyncio.sleep(wait)
await user.remove_roles(role)
await ctx.send(f":sound: {user} was unmuted",delete_after=15)
user的值在命令run中定义为被静音的用户,而不是命令的作者,例如??mute user#1234 30 s "reason"
2条答案
按热度按时间bq3bfh9z1#
正如另一个答案所指出的,你确实是在把它发送给你自己而不是用户,但是这个答案中的解决方案仍然是错误的。
User.send_message()
不是一个东西。你正在使用一个不存在的函数,你很惊讶它会出错。你没有在帖子中包含的错误消息也应该告诉你它不存在。要向频道或用户发送内容,请使用
Messageable.send()
。请记住,人们可以关闭他们的DM以阻止您向他们发送任何内容,这可能会给您带来另一个错误,并且批量DMing会让您的机器人被标记为垃圾邮件。
7ivaypg92#
你正在发送嵌入到机器人本身!
试试看:
如果这不起作用,请分享错误!