在与其他特定机器人的公会中时,Discord 机器人功能停止工作
Discord bot function stops working when in a guild with other specific bots
好的,所以..我已经为我的机器人创建了一个公会加入验证码。按照您认为的方式工作。用户加入,获得带有验证码的 DM,用户完成验证码,他们获得 access/a 角色。他们验证码失败,它重新生成一个新的并说再试一次。
以下代码完美无缺地工作,没有错误,除非它不能 DM 用户(不是我需要帮助的问题)。
但是,如果这与我的代码或 discord 意图或我的机器人所在的同一服务器中的其他 discord 机器人有任何关系,idk。但是当机器人单独在没有其他机器人的服务器中时,所有功能都可以完美运行。例如,当我在服务器中使用 Welcomer 机器人时。它生成验证码,将其发送给用户,然后什么都没有..没有回应,我这边没有错误。根本不值一提。用户可以发送他们想要的所有验证码答案,但他们没有得到任何回应、没有角色、没有错误或新的验证码。其余的机器人命令和代码仍然有效,并且机器人保持在线。
我知道代码可以正常工作并且功能完备,因为我刚刚与包括我自己在内的许多不同的人对其进行了多次测试。
只有当它与其他机器人在同一台服务器上时,它才会停止工作。有些机器人不会干扰,但其他机器人会干扰,我无法判断,直到我开始踢它们,直到我发现那个阻止我的机器人 DM 验证码工作的东西。就像欢迎机器人一样。我知道这听起来很奇怪,但这是真的。我花了数周时间对此进行了测试,而这正是我所发现的。老实说,我没有想法..
就像我说的,如果它与不和谐机器人的意图或我的代码有任何关系,我就不知道了。我希望这里有人能得到答案或解释。
这就是我的机器人意图。
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.
这是验证码 code/function。
@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"```fix\nHello {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!!\n\nNotes:\n1)The letters are case sensitive and are the big colorful ones.\n\n2)DM " + bot_author + " if the bot breaks or if you encounter any bugs!!\n\n-----------------------------\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="\n\n__Captcha Failed, Please Try Again__\n\n", color=discord.Color.red())
await user.send(embed=embed3)
pass
你的猜测和我的一样好。这几个星期以来一直是我的问题,现在持续了一个月..
感谢任何帮助。
由于您的 wait_for
中没有提供 check
kwarg,它将接受所有用户的输入,包括机器人 + 在机器人可见的任何频道中。
因此,当用户加入并欢迎 post 其在频道中的欢迎消息时
if msg.author.bot:
return #Ignores bots
被触发
注意,你返回而不是经过所以它returns然后你的wait_for
变得没用了
定义一个检查函数并在 wait_for
构造函数中使用以下 check
kwarg
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"```fix\nHello {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!!\n\nNotes:\n1)The letters are case sensitive and are the big colorful ones.\n\n2)DM " + bot_author + " if the bot breaks or if you encounter any bugs!!\n\n-----------------------------\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="\n\n__Captcha Failed, Please Try Again__\n\n", color=discord.Color.red())
await user.send(embed=embed3)
pass
好的,所以..我已经为我的机器人创建了一个公会加入验证码。按照您认为的方式工作。用户加入,获得带有验证码的 DM,用户完成验证码,他们获得 access/a 角色。他们验证码失败,它重新生成一个新的并说再试一次。
以下代码完美无缺地工作,没有错误,除非它不能 DM 用户(不是我需要帮助的问题)。 但是,如果这与我的代码或 discord 意图或我的机器人所在的同一服务器中的其他 discord 机器人有任何关系,idk。但是当机器人单独在没有其他机器人的服务器中时,所有功能都可以完美运行。例如,当我在服务器中使用 Welcomer 机器人时。它生成验证码,将其发送给用户,然后什么都没有..没有回应,我这边没有错误。根本不值一提。用户可以发送他们想要的所有验证码答案,但他们没有得到任何回应、没有角色、没有错误或新的验证码。其余的机器人命令和代码仍然有效,并且机器人保持在线。
我知道代码可以正常工作并且功能完备,因为我刚刚与包括我自己在内的许多不同的人对其进行了多次测试。
只有当它与其他机器人在同一台服务器上时,它才会停止工作。有些机器人不会干扰,但其他机器人会干扰,我无法判断,直到我开始踢它们,直到我发现那个阻止我的机器人 DM 验证码工作的东西。就像欢迎机器人一样。我知道这听起来很奇怪,但这是真的。我花了数周时间对此进行了测试,而这正是我所发现的。老实说,我没有想法..
就像我说的,如果它与不和谐机器人的意图或我的代码有任何关系,我就不知道了。我希望这里有人能得到答案或解释。
这就是我的机器人意图。
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.
这是验证码 code/function。
@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"```fix\nHello {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!!\n\nNotes:\n1)The letters are case sensitive and are the big colorful ones.\n\n2)DM " + bot_author + " if the bot breaks or if you encounter any bugs!!\n\n-----------------------------\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="\n\n__Captcha Failed, Please Try Again__\n\n", color=discord.Color.red())
await user.send(embed=embed3)
pass
你的猜测和我的一样好。这几个星期以来一直是我的问题,现在持续了一个月..
感谢任何帮助。
由于您的 wait_for
中没有提供 check
kwarg,它将接受所有用户的输入,包括机器人 + 在机器人可见的任何频道中。
因此,当用户加入并欢迎 post 其在频道中的欢迎消息时
if msg.author.bot:
return #Ignores bots
被触发
注意,你返回而不是经过所以它returns然后你的wait_for
变得没用了
定义一个检查函数并在 wait_for
构造函数中使用以下 check
kwarg
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"```fix\nHello {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!!\n\nNotes:\n1)The letters are case sensitive and are the big colorful ones.\n\n2)DM " + bot_author + " if the bot breaks or if you encounter any bugs!!\n\n-----------------------------\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="\n\n__Captcha Failed, Please Try Again__\n\n", color=discord.Color.red())
await user.send(embed=embed3)
pass