Проблема с кодом формы для опросов discord.py

Рейтинг: 1Ответов: 1Опубликовано: 18.02.2023

Вот недавно решил сделать код с формой для опросов.

Взял у местного программиста на гитхабе, но он не работает.

Как утверждал автор для работы этого кода нужно иметь особую роль (из дискорд сервера, где бот с таким же кодом почти) и прописать команду s.pull, смотря на тот сервер, где сам бот так настроен.

Но ни s.pull ни g.pull не работает.

Полагаю это связано с той же ролью, но не могу понять как это исправить.

Вот код:

import datetime
import discord
import asyncio
import random
import re
from discord.ext import commands
from discord.ui.view import View
from discord.ui.modal import Modal

print("Starts...")

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='g.',intents=intents)

class Poll_modal(Modal, title = '🎁 | Опрос'):
    ch = discord.ui.TextInput(label = "ID Канала:", placeholder = "Оставьте пустым, если опрос будет в этом канале", required = False)
    name = discord.ui.TextInput(label = "Тема опроса:", required = True)
    option_1 = discord.ui.TextInput(label = "Первый вариант ответа:", required = True)
    option_2 = discord.ui.TextInput(label = "Второй вариант ответа:", required = True)
    option_3 = discord.ui.TextInput(label = "Третий вариант ответа:", placeholder = "Этот вариант можно оставить пустым",required = False)

    async def on_submit(self, interaction: discord.Interaction):
        one = f":one: {self.option_1.value}"
        two = f":two: {self.option_2.value}"
        if self.option_3.value == '':
            three = ''
        else:
            three = f":three: {self.option_3.value}"


        embed = discord.Embed(
            title = '🎁 | Опрос',
            description = f"""
**{self.name.value}**
{one}
{two}
{three}""",
            color = 0x007f5c
        )
        embed.set_footer(icon_url=settings.misc.avatar_url, text=settings.misc.footer)
        embed.set_author(name = interaction.user.display_name, icon_url= interaction.user.display_avatar)

        if self.ch.value == '':
            msg = await interaction.channel.send(f'<@&{settings.roles.poll_role}>', embed=embed)
        else:
            channel = discord.utils.get(interaction.guild.channels, id = int(self.ch.value))
            message = await channel.send(f'<@&{settings.roles.poll_role}>', embed=embed)
        await message.add_reaction('1️⃣')
        await message.add_reaction('2️⃣')
        if self.option_3.value != '':
            await message.add_reaction('3️⃣')

@bot.event
async def on_message(ctx):
    if ctx.author != bot.user:
        channel = bot.get_channel(1073146856223293530)
        if channel.id == ctx.channel.id:
            await ctx.delete()
            embed = discord.Embed(title=f"От: {ctx.author.name}", description=ctx.content, color=0x3498db)
            message = await channel.send(embed=embed)
            await message.add_reaction('👍')
            await message.add_reaction('👎')
        await bot.process_commands(ctx)


@bot.command(name='hello')
async def hello(ctx):
    author = ctx.message.author
    await ctx.send(f'Hello, {author.mention}!')


bot.run("token")

Команда hello и строка с евентом работают отлично.

Ответы

▲ 1
import datetime 
import discord
import asyncio
import random
import re
import datetime
from discord.ext import commands
from discord.ui.view import View
from discord.ui.modal import Modal

print("Starts...")

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='g.',intents=intents)

class Poll_modal(Modal, title = '🎁 | Опрос'):
    ch = discord.ui.TextInput(label = "ID Канала:", placeholder = "Оставьте 
пустым, если опрос будет в этом канале", required = False)
    name = discord.ui.TextInput(label = "Тема опроса:", required = True)
    option_1 = discord.ui.TextInput(label = "Первый вариант ответа:", required = 
True)
    option_2 = discord.ui.TextInput(label = "Второй вариант ответа:", required = 
True)
    option_3 = discord.ui.TextInput(label = "Третий вариант ответа:", 
placeholder = "Этот вариант можно оставить пустым",required = False)

    async def on_submit(self, interaction: discord.Interaction):
        one = f":one: {self.option_1.value}"
        two = f":two: {self.option_2.value}"
        if self.option_3.value == '':
            three = ''
        else:
            three = f":three: {self.option_3.value}"


        embed = discord.Embed(
            title = '🎁 | Опрос',
            description = f"""
**{self.name.value}**
{one}
{two}
{three}""",
            color = 0x007f5c
        )
        embed.set_footer(icon_url=settings.misc.avatar_url, 
text=settings.misc.footer)
        embed.set_author(name = interaction.user.display_name, icon_url= 
interaction.user.display_avatar)

        if self.ch.value == '':
            msg = await interaction.channel.send(f'<@& 
{settings.roles.poll_role}>', embed=embed)
        else:
            channel = discord.utils.get(interaction.guild.channels, id = 
int(self.ch.value))
            message = await channel.send(f'<@&{settings.roles.poll_role}>', 
embed=embed)
        await message.add_reaction('1️⃣')
        await message.add_reaction('2️⃣')
        if self.option_3.value != '':
            await message.add_reaction('3️⃣')

@bot.event
async def on_message(ctx):
    if ctx.author != bot.user:
        channel = bot.get_channel(1073146856223293530)
        if channel.id == ctx.channel.id:
            await ctx.delete()
            embed = discord.Embed(title=f"От: {ctx.author.name}", 
 description=ctx.content, color=0x3498db)
            message = await channel.send(embed=embed)
            await message.add_reaction('👍')
            await message.add_reaction('👎')
        await bot.process_commands(ctx)


@bot.command(name='hello')
async def hello(ctx):
    author = ctx.message.author
    await ctx.send(f'Hello, {author.mention}!')


bot.run("token")