Below is code for my Discord bot.
def dice(bot,update):
bot.send_dice.message(chat_id = update.message.chat_id)
updater = Updater(API_KEY,use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('dice',dice))
This code produces this error:
AttributeError: 'Update' object has no attribute 'send_dice'
please help, I have no idea how this works
The error is likely due to the fact that you're using the old-style signature def callback(bot, update), while on python-telegram with version >=12. The new syntax is def callback(update, context), where context is an object that contains the bot instance as context.bot and also a bunch of other utility functionailty.
Please see the transition guide to version 12 (and also the one for version 13, if applicable) for details.
Disclaimer: I'm the maintainer of python-telegram-bot.
Related
I am trying to create a function of my discord bot where on a command it prints the names of online members in a specific channel to the chat. I can get the bot to print all members of a channel but cannot get it to isolate only the online members.
My current code is thus
linkchannel = int(message.channel.topic)
channel = client.get_channel(linkchannel)
members = channel.members
names = [] #(list)
for member in members:
if member.Status == discord.client.Status.online:
names.append(member.name)
print(names)
await message.channel.send(names)
it returns the error 'Member has no attribute Status' despite the docs stating it does. It has also previously failed to identify discord.Status as a valid path despite the documentation stating it is. Any help would be appreciated. My bot has access to all permissions including all privileged gateway intents
You need member intents for this to function.
For more information on how to enable member intents, read the official documentation, or this answer that explains it quite clearly.
I've started receiving a warning (when I start the bot):
disnake\ext\commands\interaction_bot_base.py:733: SyncWarning: Failed to overwrite commands in <Guild id=889176263992963142> due to 403 Forbidden (error code: 50001): Missing Access
warnings.warn(
Tried locating it, but the line this error supposedly occurs at is (the last one):
async def _sync_application_command_permissions(self) -> None:
# Assuming that permissions and commands are cached
if not isinstance(self, disnake.Client):
raise NotImplementedError(f"This method is only usable in disnake.Client subclasses")
The warning I've sent is the full message. I've also tried going back a few version, when I am sure that it didn't produce this warning, but it started appearing now.
The bot was invited with applications.commands scope included.
Library used is disnake, if someone could create a specific tag for it, that would be nice.
The issue was, trying to access test_guild while not being present there (I've kicked the bot from one of two guilds it was at).
bot = commands.Bot(
command_prefix=commands.when_mentioned_or("!"),
test_guilds=[guild_id1, guild_id2],
intents=disnake.Intents.all()
)
Removing this extra guild solved the issue.
I started working with Pyrebase recently and it's been going smoothly. However, today, I started getting an error from an update statement that I wasn't getting before.
I didn't change anything in the code.
The statement triggering the TypeError is:
db.child("teams").child(x['creatorId']).update({'player01':creator_name,'player02':str(request)})
'creatorId' is a key from a dictionary I've saved in a JSON file. In a previous step, I ran a loop to get the value of creatorId, which is what I'm using here.
creator_name is a discord username (username#discriminator):
creator = bot.get_user(x['creatorId'])
creator_name = creator.name + "#" + creator.discriminator
request is also a discord username: request = bot.get_user(payload.user_id). I'm using str() here because it doesn't let me update Firebase with a Member object, and therefore, I have to turn request (which is a Discord username) into a string.
The error is:
TypeError: 'Pyre' object is not subscriptable
Also, I'm running the code on Repl.it, and a few times before, Repl.it showed me errors where none were there, so that may also be a cause. But that usually solved itself when I refreshed the page. This error does not solve itself like that.
Any and all help is appreciated. Please let me know if I've forgotten any important details.
Ok, figured it out.
What I did was this:
I created a new variable to store x['CreatorId']:
creator_id = x['creatorId']
Afterwards, I replaced the x['creatorId'] in the update statement with the new variable. So, the new code looks like this:
db.child('teams').child(creator_id).update({'player01':creator_name,'player02':str(request)})
What I'm trying to do: If someone doesn't know the prefix, they can mention the bot and use the mention instead. After some research, I had found How to send commands to a bot by name? This made me want to try using the commands.when_mentioned or commands.when_mentioned_or functions alongside my custom prefix.
My problem: The bot either only responds to the mention (while throwing errors at me), or does not respond at all.
Here is the custom prefix code I am using: How to get a customizable prefix discord.py
Here is the client definition with the command_prefix:
intents = discord.Intents.all()
client = commands.Bot(
command_prefix= (get_prefix),
description='A bot who wants your toes',
owner_id=(394506589350002688),
case_insensitive=True,
intents=intents
)
Below I have listed what I have tried. I am not sure what to try next, so I will be grateful for any help provided.
Trial 1:
command_prefix= commands.when_mentioned_or((get_prefix))
Result:
TypeError: Iterable command_prefix or list returned from get_prefix must contain only strings, not function
Trial 2:
command_prefix= commands.when_mentioned or (get_prefix)
Result: No error, but bot no longer responds to custom prefix as seen below.
Trial 3:
command_prefix= commands.when_mentioned and (get_prefix)
Result: No error, but bot no longer responds to mention as seen below.
when_mentioned_or is supposed to be passed a list of prefixes, not a function for getting that list. It's easy enough to modify though:
def when_mentioned_or_function(func):
def inner(bot, message):
r = func(bot, message)
r = commands.when_mentioned(bot, msg) + r
return r
return inner
message = client.receive_message()
This code is now deprecated and when searching for a solution it seems I am the only one with this issue.
I get this warning:
DeprecatedWarning: receive_message is deprecated as of 2.3.0. We
recommend that you use the .on_message_received property to set a
handler instead of message = client.receive_message()
If you have a possible solution, please post it here.
I am running the latest python 3.9 and the latest Azure IoT device library.
You're trying to use a method that's no longer supported (because it's deprecated). As the error message says, the correct way to handle C2D messages is to use an event handler. There is a good example of that here
The part you will be interested in is:
# define behavior for receiving a message
# NOTE: this could be a function or a coroutine
def message_received_handler(message):
print("the data in the message received was ")
print(message.data)
print("custom properties are")
print(message.custom_properties)
print("content Type: {0}".format(message.content_type))
print("")
# set the mesage received handler on the client
device_client.on_message_received = message_received_handler