当与其他特定机器人在公会中时,Discord机器人功能停止工作



好的,所以…我为我的机器人制作了一个公会加入captcha。按照你认为的方式工作。用户加入,获得带有captcha的DM,用户完成captcha,他们获得访问/a角色。他们没有通过captcha,它重新启动一个新的captcha并说再试一次。

以下代码工作完美,没有错误,除非它不能DM用户(这不是我需要帮助的问题(。无论如何,如果这与我的代码、不和谐意图或我的机器人所在的同一服务器中的其他不和谐机器人有任何关系,我会说……但当机器人单独在服务器中,没有其他机器人时,所有功能都能完美地工作。当我在服务器上有机器人的时候,比如Welcomer机器人。它生成captcha,发送给用户,然后什么都没有。。没有回应,我这边没有错误。什么都没有。用户可以发送他们想要的所有captcha答案,但他们没有得到响应,没有角色,没有错误或新的captcha。其余的机器人命令和代码仍然有效,机器人仍然在线。

我完全知道代码的工作原理和功能,因为我刚刚与包括我自己在内的许多不同的人进行了多次测试。

只有当它与其他机器人在同一台服务器上时,它才会停止工作。有些机器人不会干扰,但另一些机器人会干扰,我无从得知,直到我开始踢它们,直到我发现有人阻止我的机器人DM captcha的东西工作。就像welcomer机器人。我知道这听起来很奇怪,但这是真的。我花了几个星期的时间来测试这一点,这就是我所发现的。我真的没有主意了。。

就像我说的,idk如果它与不和机器人意图或我的代码有任何关系。我希望这里有人能给出答案或解释。

这就是我的机器人意图。

intents = discord.Intents.default()
intents.members = True
BOT_Prefix=("t.", "T.")
eye = commands.Bot(command_prefix=BOT_Prefix, intents=intents) #eye replaces Client. So instead of @Client.command/event it's @eye.command/event.

这就是captcha代码/函数。

@eye.event
async def on_member_join(user: discord.Member):
while True:
verified = discord.utils.get(user.guild.roles, id=649739504940351489)
res = r.get("https://captcha.manx7.net/insecure/new", headers={"captcha-length":"5"}).json();
if res['error']:
print(res['error'] + " - Manx7 Error")
user.send("Something went wrong while trying to set-up a captcha session, please contact `" + bot_author + "` for help.")
return
captcha_answer = res['response']['code']
embed = discord.Embed(title="Server Captcha", description=f"```fixnHello {user.name},nYou will not be able to gain access to the server until you complete this captcha.nPlease Type The Follwoing Below To Verify!!nnNotes:n1)The letters are case sensitive and are the big colorful ones.nn2)DM " + bot_author + " if the bot breaks or if you encounter any bugs!!nn-----------------------------nCaptchca API - https://captcha.manx7.net/```")
embed.set_footer(text=f"{botver} by Ori", icon_url='https://cdn.discordapp.com/attachments/850592305420697620/850595192641683476/orio.png')
embed.set_image(url=res['response']['image'])
await user.send(embed=embed)
#Everything above this line/message works fine every time. 
msg = await eye.wait_for("message")
if msg.author.id == eye.user.id:
return #Ignores itself (Used to send captcha, error then send it again when a user joined. This stops that.)
if msg.author.bot: 
return #Ignores bots
if msg.content == captcha_answer:
embed2 = discord.Embed(title="Verified!", description=f":white_check_mark: Thank you for verifying!. You have now been given access to the server!", color=discord.Color.green())
embed2.set_footer(text=f"{botver} by Ori", icon_url='https://cdn.discordapp.com/attachments/850592305420697620/850595192641683476/orio.png')
await user.send(embed=embed2)
await user.add_roles(verified, reason="None")
break
else:
embed3 = discord.Embed(title="Error!", description="nn__Captcha Failed, Please Try Again__nn", color=discord.Color.red())
await user.send(embed=embed3)
pass

你的猜测和我的一样好。这是我几个星期以来的一个问题,现在已经持续了一个月。。

感谢您的帮助。

由于您的wait_for中没有提供checkkwarg,它将接受所有用户的输入,包括机器人程序可见的任何通道中的机器人程序+。

因此,当用户加入并欢迎在通道中发布欢迎信息时

if msg.author.bot: 
return #Ignores bots

被触发

请注意,您是返回而不是通过,因此它返回,之后您的wait_for将成为无用的

定义一个检查函数,并在wait_for构造函数中使用以下checkkwarg

def check(m):
return m.author == user and m.channel == x.channel

所以你的代码现在变成:

@eye.event
async def on_member_join(user): # you need not typecast in an event, it by default knows that user is a discord.Member object
while True:
verified = discord.utils.get(user.guild.roles, id=649739504940351489)
res = r.get("https://captcha.manx7.net/insecure/new", headers={"captcha-length":"5"}).json();
if res['error']:
print(res['error'] + " - Manx7 Error")
user.send("Something went wrong while trying to set-up a captcha session, please contact `" + bot_author + "` for help.")
return
captcha_answer = res['response']['code']
embed = discord.Embed(title="Server Captcha", description=f"```fixnHello {user.name},nYou will not be able to gain access to the server until you complete this captcha.nPlease Type The Follwoing Below To Verify!!nnNotes:n1)The letters are case sensitive and are the big colorful ones.nn2)DM " + bot_author + " if the bot breaks or if you encounter any bugs!!nn-----------------------------nCaptchca API - https://captcha.manx7.net/```")
embed.set_footer(text=f"{botver} by Ori", icon_url='https://cdn.discordapp.com/attachments/850592305420697620/850595192641683476/orio.png')
embed.set_image(url=res['response']['image'])
x = await user.send(embed=embed)
#Everything above this line/message works fine every time. 
def check(m): # m is a Message object 
return m.author == user and m.channel == x.channel # return only if the user responded in bot's dms and user is the person who triggered the event
msg = await eye.wait_for("message", check=check)
if msg.author.id == eye.user.id:
return #Ignores itself (Used to send captcha, error then send it again when a user joined. This stops that.)
if msg.content == captcha_answer:
embed2 = discord.Embed(title="Verified!", description=f":white_check_mark: Thank you for verifying!. You have now been given access to the server!", color=discord.Color.green())
embed2.set_footer(text=f"{botver} by Ori", icon_url='https://cdn.discordapp.com/attachments/850592305420697620/850595192641683476/orio.png')
await user.send(embed=embed2)
await user.add_roles(verified, reason="None")
break
else:
embed3 = discord.Embed(title="Error!", description="nn__Captcha Failed, Please Try Again__nn", color=discord.Color.red())
await user.send(embed=embed3)
pass

最新更新