我正在尝试为模因创建一个 <!DOCTYPE html>
<html>
<head>
<style>
p, h1, h2, h3, h4, h5, h6 {
color: #ffffff;
}
.btn-group {
top: 0;
left: 0;
position: absolute;
width: 100%;
background-color: #282a35;
border-bottom: 8px solid #303740;
}
.btn-group .button {
background-color: #282a35; /* Dark */
color: #ffffff;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
float: left;
border: none;
}
.btn-group .button:hover {
background-color: #000000;
}
.btn-group .notbutton {
background-color: #282a35; /* Dark */
color: #282a35;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: cursor;
float: left;
border: none;
border-bottom: 4px solid #303740;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
/*
Introduced in IE 10.
See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/
*/
-ms-user-select: none;
user-select: none;
}
</style>
</head>
<body style="background-color:#1a1a1b;">
<form action="https://www.google.com">
<div class="btn-group">
<button class="button">Area</button>
<button class="button">Area1</button>
<button class="button">Area2</button>
</div>
<p style="clear:both"><br><br><br>the website</p>
</body>
</html>
。当其中包含 listener
时,机器人将响应该消息。它必须发送一个模因。我为此目的使用 Praw。
这是我写的代码:
"meme"
注意:我已经在某些行上方定义了 @nd.listen()
async def on_message(message):
if message.author == nd.user:
return
def findCoindences(w):
return re.compile(r'\b({0})\b'.format(w)).search
content = message.content
reaction = "?"
subreddit = reddit.subreddit("memes")
for submission in subreddit.random():
submission_link = submission.url
if findCoindences('meme')(content.lower()):
await message.reply(submission_link)
await message.add_reaction(f"<{reaction}>")
。这不是我猜的原因。
每当我在聊天中发送 reddit
时,它每次都会发送相同的模因。我希望它有所不同,但不知道我在哪里遇到了这个问题。
答案 0 :(得分:1)
您无需迭代任何内容。 Praw 提供了一种方法,允许您从 subreddit 中获取随机提交。
文档: random()
代码:
@nd.listen()
async def on_message(message):
if message.author == nd.user:
return
def findCoindences(w):
return re.compile(r'\b({0})\b'.format(w)).search
content = message.content
reaction = "?"
if findCoindences('meme')(content.lower()):
random_submission = reddit.subreddit('memes').random()
await message.reply(random_submission.url)
await message.add_reaction(f"<{reaction}>")
<块引用>
注意:我已将 random_submission 移到 If-statement
内,因为如果消息未显示“meme”,则您无需查找提交。这只会浪费速率限制。