将文本逐行发送到不和谐的网络钩子

时间:2021-03-04 20:09:39

标签: discord.py webhooks

我正在尝试通过 discord webhook 逐行将文本从单词表发送到 discord 频道。下面的脚本出于某种原因只发送单词列表中的最后一行。

from discord_webhook import DiscordWebhook

with open('wordlist.txt','r') as lines:    
    for line in lines:
                webhook = DiscordWebhook(url='webhookurlhere', content=lines.readline()

response = webhook.execute()

1 个答案:

答案 0 :(得分:0)

from discord_webhook import DiscordWebhook

file = open("wordlist.txt", 'r')
lines = file.readlines()

for line in lines:
    webhook= DiscordWebhook(url='myurl', content= line)

response = webhook.exectute()
file.close()

看来您在 discordwebhook 调用中缺少一个右括号。我还以稍微不同的方式构建了文件的阅读方式,只是对我来说更容易阅读。看看这是否适合您。