所以我需要检测一个链接,但我不确定如何检测。打印的错误是“属性错误:‘str’对象没有‘send’属性。
@bot.command()
async def create(ctx):
embed1 = discord.Embed()
embed1.add_field(name="To start, send your vip link.", value="**__MUST__ be a roblox football fusion link, sending any other link will result in a 48h mute, as well as a loss of your PUG Host role.**", inline=True)
url = '\http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
embed2 = discord.Embed()
embed2.add_field(name="New PUG!", value=f"{url}", inline=True)
msg_sent = await ctx.send(embed=embed1)
await url.send(embed=embed2)
顺便说一下,这是一个由两部分组成的命令。
答案 0 :(得分:1)
我相信,这可能就是您要找的:
@client.command()
async def create(ctx):
embed = discord.Embed (
title = 'To start, send your vip link.',
description = '__MUST__ be a roblox football fusion link, sending any other link will result in a 48h mute, as well as a loss of your PUG Host role.'
)
message = await ctx.send(embed = embed)
def check(message):
return message.author == ctx.author
# This function is used to check if the message received is a valid URL
def checkURL(url):
regex = 'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
return re.match(regex, url) is not None
try:
url = await client.wait_for('message', check = check, timeout = 60.0)
if (checkURL(url.content)):
embed = discord.Embed (
title = 'New PUG!',
description = url.content
)
await ctx.send(embed = embed)
else:
await ctx.send('Sorry, that is not a valid roblox football fusion link.')
except:
await message.delete()
注意:记得导入 re
模块。
注意:对于 regex
部分,我只使用了问题中的字符串。您必须进一步细化它以检查 url 是否与特定域匹配。例如,您只能检查 google.com 链接。了解有关 regex
here 的更多信息。