0
channel = client.get_channel
    if message.content.lower().startswith('experiment'): 
        moji = await client.get_channel.send("https://c.tenor.com/R_itimARcLAAAAAd/talking-ben-yes.gif")
        emoji = [":blue_circle:"]
        for experiment in emoji:
            await client.add_reaction(emoji)

What I want the bot to do is when the user types 'experiment' the bot will send the link to the photo and it will attach the emoji to it. It gives me this error.

Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\13129\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "c:\Users\13129\Desktop\Python Bot\Ben.py", line 50, in on_message moji = await client.get_channel.send("https://c.tenor.com/R_itimARcLAAAAAd/talking-ben-yes.gif") AttributeError: 'function' object has no attribute 'send'

I tried changing a few things on line 20 but nothing seems to be working!

2 Answers 2

1

Bot.get_channel is a method which takes a channel_id as a positional argument and gets you a Union[StageChannel, VoiceChannel, CategoryChannel, TextChannel, Thread (if you are on master)] if the ID you pass to it matches one it has in its internal cache (this requeires members intent)

you can't do get_channel.send(), get_channel is a method, or in other words, a bound function to Bot class.

here is an example usage:

channel = bot.get_channel(CHANNEL_ID)
await channel.send("hello there!")

also,

client.add_reaction(emoji) is not a thing

Message.add_reaction is. await channel.send() returns a Message object which you can store in a variable and then add your emoji

message = await channel.send("hello there!")
for emo in emoji:
    await message.add_reaction(emo)

and I am pretty sure that you need the unicode of that emoji and the string would raise UnknownEmoji error, but if it doesn't then it's fine. If it does though, just use "\N{Large Blue Circle}" instead :blue_circle: and that should fix it.

Sign up to request clarification or add additional context in comments.

9 Comments

The top part worked but it's not adding the reaction. Its giving this error: File "C:\Users\13129\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\message.py", line 69, in convert_emoji_reaction raise InvalidArgument('emoji argument must be str, Emoji, or Reaction not {.__class__.__name__}.'.format(emoji)) discord.errors.InvalidArgument: emoji argument must be str, Emoji, or Reaction not list.
message.add_reaction(experiment) instead of message.add_reaction(emoji) in your code
@Rose It kinda worked. It did add the reaction to the users response but I want it to add to the bots response. Now when the user types "experiment" it adds the circle there but the bot posts the picture. Is there a way I can get it to add a reaction to the bots response?
you have to do mess = await channel.send("your bot's message") and then await mess.add_reaction(experiment) in the for loop instead of message.add_reaction if you have a use-case for it later
Its telling me Channel is not defined in mess = await channel.send("") Is it possible for me to have it automatically know what channel its in?
|
0

You should be doing client.get_channel() with something in the brackets like a channel ID, not client.get_channel If not how will they know what channel to send it to.

For Prefixed Commands

@client.command()
async def command_name(ctx)
    await ctx.send()
    # Sends to what ever channel the command was sent in

7 Comments

How would I get the bot to send the link then? Also this is a bot used and different discords so there can't be one specific channel ID. Can you possibly send the message as how it would look in the code?
What type of command are you using, slash or prefixed
this is on_message @FishballNooodles
When the user sends "experiment" the bot will send the photo and attach the reaction to it. Is it not possible to do this with on_message?
If using on_message, Do await message.channel.send(). Remove all the await client.get_channel
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.