Discord.py 带有方括号的链接
Discord.py links with box brackets around them
elif message.content.find("{memes") != -1:
a = "https://imgur.com/Jlhfk4F"
b = "https://i.imgur.com/seC2lyP.jpg?play"
c = "https://imgur.com/CZyB2Zz"
d = "https://imgur.com/N4KQcJ5"
e = "https://imgur.com/kuDuY0b"
f = "https://imgur.com/z6uMw0q"
g = "https://imgur.com/gAa9Poq"
h = "https://imgur.com/7dh4NFR"
i = "https://imgur.com/ox8BQqv"
j = "https://imgur.com/iLMRDZY"
k = "https://imgur.com/UG0sLCd"
l = "https://imgur.com/peCVHpF"
m = "https://imgur.com/XgBE3Pu"
n = "https://i.imgur.com/zoBayy9.jpg?play"
o = "https://imgur.com/2wDk09q"
p = "https://imgur.com/mz62oay"
secret = random.choices([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p])
await message.channel.send(secret)
这是我用于我的机器人的随机 meme 命令的当前代码。出于某种原因,机器人发送的链接每边都带有方括号,就像这样
['https://imgur.com/7dh4NFR']
有人可以帮助我吗?
您正在使用 random.choices
, which returns a list. Use random.choice
。即returns一个元素。
secret = random.choice([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p])
以下是 Python 文档中的相关片段:
random.choice(seq)
Return a random element from the non-empty sequence seq. If seq is empty, raises IndexError.
random.choices(population, weights=None, *, cum_weights=None, k=1)
Return a k sized list of elements chosen from the population with replacement. If the population is empty, raises IndexError.
方法 random.choices
return 是一个结果列表,因为它旨在能够 return 多个结果。您应该改为使用 random.choice
.
这是因为您使用的是 random.choices 而不是 random.choice。 random.choices returns k个选项的列表,默认1个,而random.choice returns每次只有一个。
elif message.content.find("{memes") != -1:
a = "https://imgur.com/Jlhfk4F"
b = "https://i.imgur.com/seC2lyP.jpg?play"
c = "https://imgur.com/CZyB2Zz"
d = "https://imgur.com/N4KQcJ5"
e = "https://imgur.com/kuDuY0b"
f = "https://imgur.com/z6uMw0q"
g = "https://imgur.com/gAa9Poq"
h = "https://imgur.com/7dh4NFR"
i = "https://imgur.com/ox8BQqv"
j = "https://imgur.com/iLMRDZY"
k = "https://imgur.com/UG0sLCd"
l = "https://imgur.com/peCVHpF"
m = "https://imgur.com/XgBE3Pu"
n = "https://i.imgur.com/zoBayy9.jpg?play"
o = "https://imgur.com/2wDk09q"
p = "https://imgur.com/mz62oay"
secret = random.choices([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p])
await message.channel.send(secret)
这是我用于我的机器人的随机 meme 命令的当前代码。出于某种原因,机器人发送的链接每边都带有方括号,就像这样
['https://imgur.com/7dh4NFR']
有人可以帮助我吗?
您正在使用 random.choices
, which returns a list. Use random.choice
。即returns一个元素。
secret = random.choice([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p])
以下是 Python 文档中的相关片段:
random.choice(seq)
Return a random element from the non-empty sequence seq. If seq is empty, raises IndexError.
random.choices(population, weights=None, *, cum_weights=None, k=1)
Return a k sized list of elements chosen from the population with replacement. If the population is empty, raises IndexError.
方法 random.choices
return 是一个结果列表,因为它旨在能够 return 多个结果。您应该改为使用 random.choice
.
这是因为您使用的是 random.choices 而不是 random.choice。 random.choices returns k个选项的列表,默认1个,而random.choice returns每次只有一个。