【发布时间】:2021-05-27 21:19:58
【问题描述】:
我已经创建了支持命令。但我希望它更先进。一切都在我的代码中运行,但我想添加一个功能,我的机器人将使用某人 dmed bot 的消息内容向我发送消息。好吧,我知道这很令人困惑,但让我用我的代码解释一下:
import discord
from discord.ext import commands
import DiscordUtils
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix = "=", intents = intents)
@client.command(pass_context=True)
async def support(ctx):
author = ctx.author
await ctx.message.add_reaction('<a:check12:810961073746345985>')
embed = discord.Embed(
title = 'What do you want to do?',
description = '',
color = 0
)
embed.set_footer(text='007 support')
embed.add_field(name='Report a bug, react:', value="1️⃣", inline=False)
embed.add_field(name='Submit suggestion, react:', value="2️⃣", inline=False)
embed.add_field(name='Talk to bot owner, react:', value="3️⃣", inline=False)
msg = await ctx.author.send(embed=embed)
await msg.add_reaction("1️⃣")
await msg.add_reaction("2️⃣")
await msg.add_reaction("3️⃣")
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["1️⃣", "2️⃣", "3️⃣"]
while True:
try:
reaction, user = await client.wait_for("reaction_add", timeout=60, check=check)
if str(reaction.emoji) == "1️⃣":
embed = discord.Embed(color=0)
embed.set_author(name=f"007", icon_url="")
embed.add_field(name='Report a bug', value="Describe a bug here. 007 will try to fix it.")
embed.set_footer(text="007 support")
await ctx.author.send(embed=embed)
user = client.get_user(int(MY_ID))
await user.send(embed=embed)
if str(reaction.emoji) == "2️⃣":
embed = discord.Embed(color=0)
embed.set_author(name=f"007", icon_url="")
embed.add_field(name='Submit suggestion', value="Submit your suggestion here. 007 owner will review it as fast as possible")
embed.set_footer(text="007 support")
await ctx.author.send(embed=embed)
user = client.get_user(int(MY_ID))
await user.send(embed=embed)
if str(reaction.emoji) == "3️⃣":
embed = discord.Embed(color=0)
embed.set_author(name=f"007", icon_url="")
embed.add_field(name='Talk to a owner', value='Your code is 240348. Type this in any channel: ```=talk <your code>``` then follow instructions')
embed.set_footer(text="007 support")
await ctx.author.send(embed=embed)
except asyncio.TimeoutError:
await msg.delete()
正如您在 options(1, 2) 中看到的,机器人将嵌入发送到 ctx.author 和我。但我希望机器人向我发送嵌入消息,并用作者姓名回复作者的答案。例如:
if str(reaction.emoji) == "2️⃣":
embed = discord.Embed(color=0)
embed.set_author(name=f"007", icon_url="")
embed.add_field(name='Submit suggestion', value="Submit your suggestion here. 007 owner will review it as fast as possible")
embed.set_footer(text="007 support")
await ctx.author.send(embed=embed)
user = client.get_user(int(MY_ID))
await user.send(embed=embed)
await user.send(f'{answer} {author.name}
最后一行是作者的回答/信息。这有可能做到这一点吗?如果是,请告诉我如何。谢谢
【问题讨论】:
-
我不确定我理解你想要什么。您是否希望当有人向您的机器人发送 DM 时,该机器人会向您发送一条 DM,其中包含向您的机器人发送 DM 的用户的名称以及发送的消息?
-
是的,我就是这个意思。
标签: python python-3.x discord.py