如何通过discord.py bot从网站向discord频道发送消息

2024-06-03 06:31:45 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我试图为我的discord.py机器人制作一个仪表板 所以我做了一个页面,在那里我将输入我的姓名、电子邮件和电话号码,然后我点击提交,另一个页面将打开,在那里我将看到这些值 因此,我想将discord.py bot连接到它,以便在我单击“提交”时它将向特定频道发送嵌入 我不知道怎么做,我尝试了很多东西,但是没有用

from flask import Flask, render_template, redirect, url_for, request


import discord
from dhooks import Webhook, Embed
from discord.ext import commands, tasks



app = Flask(__name__)
@app.route('/yami/home/posts')
def posts():
   return render_template('posts.html')

@app.route('/verified', methods = ['POST', 'GET'])
async def verified():
    if request.method == "POST":
        result = request.form
        channel_entry = 694563592518893601
        msg_entry = 'test'


        channel = client.get_channel(channel_entry)
        await channel.send(msg_entry)

        return render_template("verified.html", result = result) 
<!--posts-->
{% extends "base.html" %}
<!--HEAD-->
{% block head %}
<title>TEST posts 1</title>

{% endblock %}
<!--HEAD end-->

<!--STYLE-->
{% block style %} {% endblock %}
<!--STYLE end-->

<!--BODY-->
{% block body %}
<div class="center">
    <h1>This is posts</h1>

     <div class="side">
         <a href="index">Click to go to index</a><br>
         <a href="home">click to go to home</a><br>
         <a href="new">Click to go to new</a><br>
           <a href="/result">click to go to result</a><br>
    <a href="/student">click to go to student</a><br>

          <a href="verified">click to go to verified</a>
     </div>
</div>
{% for s in stuff1%}
<h1>{{s.title}}</h1>
<p>{{s.content}}</p>
{% endfor %}
<form action="/verified" method="POST">
    <div class="side">
        <h3>Sign up</h3>

    Author:<input type="text" name="author">
        Email:<input type="email" name="email">
        Phone no.:<input type="number" name="phone no">
    Submit:<input type="submit" value="submit">
    </div>



</form>
{% endblock %}
<!--BODY end-->
<!--verified-->
{% extends "base.html" %}
<!--HEAD-->
{% block head %}
<title>TEST posts 1</title>

{% endblock %}
<!--HEAD end-->

<!--STYLE-->

{% block style %} {% endblock %}
<!--STYLE end-->

<!--BODY-->
{% block body %}
<div class="side">
   <a href="/yami/home/index">Click to go to index</a><br>
    <a href="/yami/home/home">click to go to home</a><br>
    <a href="/yami/home/new">Click to go to new</a><br>
     <a href="/yami/home/posts">click to go to posts</a><br>
      <a href="/result">click to go to result</a><br>
    <a href="/student">click to go to student</a><br>
</div>
{% for key, value in result.items() %}
<h1><ins>{{ key }} :</ins></h1>
<h3>{{ value }} </h3>
{% endfor %}



{% endblock %}

这些是与2页相关的代码


Tags: tobrdivgohomechannelresultblock