Comments (6)
Can you give me full code?
from dislash.py.
I receive this error only on DMs, the 2nd message to send gives me the error but ctx["channel"]
is None at the beginning of the function.
import os
import discord
from discord.ext import commands
from dislash import SlashClient, SelectMenu, SelectOption, Option, Type
from dotenv import load_dotenv
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from orm.tables import Player
from classes.classes import Card
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD_ID = int(os.getenv('GUILD_ID'))
CONNECT_STRING = os.getenv('CONNECT_STRING')
engine = create_engine(CONNECT_STRING)
Session = sessionmaker(bind=engine)
session = Session()
intents = discord.Intents().all()
bot = commands.Bot(command_prefix='!', intents=intents)
slash = SlashClient(bot)
@slash.command(
name="get_player",
options=[
Option("name", "Specify any player", Type.STRING, required=True)
]
)
async def get_player(ctx, name):
players = session.query(Player).filter(Player.name.like("%" + name + "%")).limit(5).all()
msgs = []
if len(players) == 0:
await ctx.send(embed=discord.Embed(
title="No player with name"
))
return
elif len(players) == 1:
chosen_card = Card(name=players[0].name, slug=players[0].slug)
else:
for player in players:
emb = discord.Embed(
title=f"{player.name}",
color=ctx.author.color
)
card = Card(name=player.name, slug=player.slug)
if card.image:
emb.set_image(url=card.image)
# Error here when sending the 2nd embed
msgs.append(await ctx.reply(embed=emb))
msg = await ctx.send(
"Choose a player",
components=[
SelectMenu(
custom_id="choose_player",
placeholder="Choose a player",
max_values=1,
options=[
SelectOption(player.name, player.slug)
for player in players
]
)
]
)
def check(inter):
return ctx.author == inter.author
# Wait for a menu click under the message you've just sent
inter = await msg.wait_for_dropdown(check)
# Tell which options you received
option = inter.select_menu.selected_options[0]
for message in msgs:
await message.delete()
await msg.delete()
chosen_card = Card(name=option.label, slug=option.value)
embed = discord.Embed(
title=f"Chosen card is {chosen_card.name}"
)
embed.set_image(url=chosen_card.image)
await ctx.send(embed=embed)
await ctx.send(embed=discord.Embed(
title="Error here when len(players) == 1"
))
bot.run(TOKEN)
from dislash.py.
Okay, here's the problem:
ctx.reply
(as well as ctx.send
(alias for reply
), ctx.respond
and ctx.create_response
(alias for respond
)) can never be called more than once, because these methods create a response for a given interaction. One interaction can only have one response.
Instead of attempting to create multiple responses, you can use ctx.channel.send
, which can be used an unlimited amount of times
from dislash.py.
I tried that but it doesn't even send 1 message, because ctx.channel is None.
Moreover, ctx.send works when it's not the 1st time that someone interacts with the bot
from dislash.py.
ctx.channel being None is super weird, maybe it's related to some caching reasons
Speaking of ctx.send working more than once, it indeed should work like that, because it automatically detects whether to use create_response
or channel.send
, I forgot to mention that
from dislash.py.
What I don't understand is that it doesn't happen when I use @discord.command
instead of @slash.command
from dislash.py.
Related Issues (20)
- Disable auto-registration of slash commands HOT 5
- Add Select Menu Disabling HOT 1
- "don't nest sub_command_groups and sub_commands to the same parent" HOT 6
- Unregistering a slash command at runtime? HOT 1
- Slash command interaction is expired on arrival HOT 4
- Sending a file in a followup's ephemeral Message will throw a 'Cannot Send Empty Message' error HOT 1
- Slash Command duplicate and wont change name HOT 3
- Reset Cooldown Doesn't Work HOT 2
- Interaction bug HOT 4
- Use versions for pip packages HOT 4
- if load extension, existing command is deleted HOT 1
- Interactable buttons on slash commands? HOT 1
- ModuleNotFoundError when trying to import dislash HOT 1
- TypeError: object of type 'ActionRow' has no len() HOT 2
- TypeError: emoji() takes 1 positional argument but 2 were given HOT 2
- library crash HOT 5
- Slash command not working
- ERROR IN DOCS
- typing mismatch python version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dislash.py.