I am extremely new to this (started experimenting with it today) and am trying to make a slash command that will create a poll using a poll class i found in documentation but can't figure out how to get it to actually send.
here is my bot code not including some other slash commands and the ending run command
import discord
from discord.ext import commands
from discord import app_commands
from discord import Color as c
from discord import Poll
class Client(commands.Bot):
async def on_ready(self):
print(f'Logged on as {self.user}!')
# sends message when bot is ready
try:
guild = discord.Object(id=1009126140633415730)
synced = await self.tree.sync(guild=guild)
print(f'Synced {len(synced)} commands to guild {guild.id}')
# syncs slash commands to server
except Exception as e:
print(f'Error syncing commands: {e}')
# prints error message if syncing fails
async def on_message(self, message):
if message.author == self.user:
return
# stops bot from replying to itself
if message.content.startswith('hello'):
await message.channel.send(f'Hi there {message.author}!')
# says hi there when user says hello
async def on_reaction_add(self, reaction, user):
await reaction.message.channel.send('You reacted')
# says when you react to message
intents = discord.Intents.default()
intents.message_content = True
client = Client(command_prefix="!", intents=intents)
GUILD_ID = discord.Object(id=1009126140633415730)
@client.treemand(name="repo", description="Create a poll to see who's free for REPO", guild=GUILD_ID)
async def repo(interaction: discord.Interaction):
p = discord.Poll(question="Are you free for REPO?", duration=4)
p.add_answer(text="Yes")
p.add_answer(text="No")
await interaction.response.send(poll=p)
# /REPO command
My issue is when i try to use the repo slash command in my discord server i get this error
2025-03-24 16:44:56 ERROR discord.app_commands.tree Ignoring exception in command 'repo'
Traceback (most recent call last):
File "C:\Users\Dan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\app_commands\commands.py", line 858, in _do_call
return await self._callback(interaction, **params) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Discord Bot\example_bot.py", line 93, in repo
await interaction.response.send(poll=p)
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'InteractionResponse' object has no attribute 'send'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Dan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\app_commands\tree.py", line 1310, in _call
await command._invoke_with_namespace(interaction, namespace)
File "C:\Users\Dan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\app_commands\commands.py", line 883, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\app_commands\commands.py", line 876, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'repo' raised an exception: AttributeError: 'InteractionResponse' object has no attribute 'send'
again I'm very new and am basing the code Im writing off of the code given in the video tutorial I watched in how to set up a discord bot so if a mistake seems obvious I will probably still need it pointed out to me.
also my first time using stack overflow so if you need any more details or if i should lay out anything differently please let me know
Fixed Code:
import time
import datetime
@client.treemand(name="repo", description="Create a poll to see who's free for REPO", guild=GUILD_ID)
async def repo(interaction: discord.Interaction):
p = discord.Poll(question="Are you free for REPO?", duration=datetime.timedelta(hours=4))
p.add_answer(text="Yes")
p.add_answer(text="No")
await interaction.response.send_message(poll=p)
Those who commented to use send_message were actually right, my other problem was that I needed to import and use delta time specifically for the duration to work. Thanks to everyone who replied!
I am extremely new to this (started experimenting with it today) and am trying to make a slash command that will create a poll using a poll class i found in documentation but can't figure out how to get it to actually send.
here is my bot code not including some other slash commands and the ending run command
import discord
from discord.ext import commands
from discord import app_commands
from discord import Color as c
from discord import Poll
class Client(commands.Bot):
async def on_ready(self):
print(f'Logged on as {self.user}!')
# sends message when bot is ready
try:
guild = discord.Object(id=1009126140633415730)
synced = await self.tree.sync(guild=guild)
print(f'Synced {len(synced)} commands to guild {guild.id}')
# syncs slash commands to server
except Exception as e:
print(f'Error syncing commands: {e}')
# prints error message if syncing fails
async def on_message(self, message):
if message.author == self.user:
return
# stops bot from replying to itself
if message.content.startswith('hello'):
await message.channel.send(f'Hi there {message.author}!')
# says hi there when user says hello
async def on_reaction_add(self, reaction, user):
await reaction.message.channel.send('You reacted')
# says when you react to message
intents = discord.Intents.default()
intents.message_content = True
client = Client(command_prefix="!", intents=intents)
GUILD_ID = discord.Object(id=1009126140633415730)
@client.treemand(name="repo", description="Create a poll to see who's free for REPO", guild=GUILD_ID)
async def repo(interaction: discord.Interaction):
p = discord.Poll(question="Are you free for REPO?", duration=4)
p.add_answer(text="Yes")
p.add_answer(text="No")
await interaction.response.send(poll=p)
# /REPO command
My issue is when i try to use the repo slash command in my discord server i get this error
2025-03-24 16:44:56 ERROR discord.app_commands.tree Ignoring exception in command 'repo'
Traceback (most recent call last):
File "C:\Users\Dan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\app_commands\commands.py", line 858, in _do_call
return await self._callback(interaction, **params) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Discord Bot\example_bot.py", line 93, in repo
await interaction.response.send(poll=p)
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'InteractionResponse' object has no attribute 'send'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Dan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\app_commands\tree.py", line 1310, in _call
await command._invoke_with_namespace(interaction, namespace)
File "C:\Users\Dan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\app_commands\commands.py", line 883, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\app_commands\commands.py", line 876, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'repo' raised an exception: AttributeError: 'InteractionResponse' object has no attribute 'send'
again I'm very new and am basing the code Im writing off of the code given in the video tutorial I watched in how to set up a discord bot so if a mistake seems obvious I will probably still need it pointed out to me.
also my first time using stack overflow so if you need any more details or if i should lay out anything differently please let me know
Fixed Code:
import time
import datetime
@client.treemand(name="repo", description="Create a poll to see who's free for REPO", guild=GUILD_ID)
async def repo(interaction: discord.Interaction):
p = discord.Poll(question="Are you free for REPO?", duration=datetime.timedelta(hours=4))
p.add_answer(text="Yes")
p.add_answer(text="No")
await interaction.response.send_message(poll=p)
Those who commented to use send_message were actually right, my other problem was that I needed to import and use delta time specifically for the duration to work. Thanks to everyone who replied!
Share Improve this question edited Mar 24 at 20:41 Gankick asked Mar 24 at 15:36 GankickGankick 14 bronze badges 8- can you explain what you mean by "where it points the issue to"? is there an error that you see? Can you also provide a minimally reproducible example? All we have is your repo() function not where it lives in relation to the rest of your bot code. – UnsanitizedInput Commented Mar 24 at 15:44
- Hi, just edited my post to add lots more detail, if you need any more please let me know – Gankick Commented Mar 24 at 16:55
- 1 I don't have the time to write a full answer but try replacing the send with send_message, it might work out. – Sairam Mangeshkar Commented Mar 24 at 17:23
- Just tried it, still get the same issue – Gankick Commented Mar 24 at 17:37
- I just started working on my own bot at home a few days ago. I'll try to check the code when I am home and see if I can notice the differences but from checking quickly it does seem like send_message() is the correct method. I believe I am using the @botmand() decorator and using await ctx.send("msg") – UnsanitizedInput Commented Mar 24 at 19:16
1 Answer
Reset to default 0The answer was to replace send
with send_message
and to use datetime.timedelta
for the duration of the poll.
import datetime
@client.treemand(name="repo", description="Create a poll to see who's free for REPO", guild=GUILD_ID)
async def repo(interaction: discord.Interaction):
p = discord.Poll(question="Are you free for REPO?", duration=datetime.timedelta(hours=4))
p.add_answer(text="Yes")
p.add_answer(text="No")
await interaction.response.send_message(poll=p)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744243399a4564811.html
评论列表(0条)