-1
import discord
from discord import guild
s = discord.client.Client
from discord import invite
c = 0

class X:



    def handle_response(message) -> str:
        p_message = message.lower()

        if p_message == 'hello':
            return 'Hey'

        if p_message == 'roll':
            return str(random.randint(1,6))

        if p_message == '!help':
            return "`This is a help message.`"


        if p_message == 'url':
            z = discord.Invite.code[int]
            y = guild.Guild.shard_id
            i = discord.guild.Guild.id[int]
            discord.guild.Guild.id

            def __getitem__(self, id):
                return self.__dict__[id]
            return print[id]

Here's a small snippet of my code, I've looked at tutorials online at various different places and implemented them but it seems to just give me the same type of error every time, I know I'm doing something wrong but I'm not sure quite what it is. I would appreciate the help, thanks.

I'm trying to get the code var in an integer form but it isn't working at the current moment, specifically this snippet: discord.Invite.code[int]

2 Answers 2

1

Use int() to convert objects to integers in Python. What you're doing is attempting to access an index (int) in an array, but int is not defined, nor is the object an array.

Doing something like: z = int(discord.Invite.code) should convert it to an int.

-1

import random

def handle_message(p_message): if p_message == 'hello': return 'Hey'

elif p_message == 'roll':
    return str(random.randint(1, 6))

elif p_message == '!help':
    return "`This is a help message.`"

elif p_message == 'url':
    z = discord.Invite.code  # this line has an issue, see explanation below
    y = guild.Guild.shard_id  # this line also has an issue, see explanation below
    i = discord.guild.Guild.id
    discord.guild.Guild.id
    
    # this function doesn't seem to be used anywhere, so I'm commenting it out
    # def __getitem__(self, id):
    #     return self.__dict__[id]
    
    # assuming you want to return the value of print[id] as a string
    return str(print[id])

Explanation of changes:

I added an import random statement to import the random module, which is used to generate random numbers in the roll command.
I added an elif statement for the url command, since it was missing.
The lines z = discord.Invite.code[int] and y = guild.Guild.shard_id have issues. It seems like you're trying to access some attributes or methods of the discord and guild modules, but the syntax is incorrect. I'm not sure what you're trying to do with these lines, so I can't provide a correction. If you can provide more context or explanation, I can help you better.
The print[id] statement in the last line also has an issue. print is a built-in function in Python, and you can't access its elements using the [id] syntax. If you can explain what you're trying to achieve with this line, I can help you better. I assumed that you want to return the value of print[id] as a string, so I used the str() function to convert it.
1
  • Thank you, I will apply these changes soon but let me clarify some things - z , y variables are unused variables but essentially I am trying to grab the server ID of the discord server using the bots. the "id" statement is the server id of the discord that I'm trying to print, once I implement the changes you have suggested I will get back to you if I need anymore help. Thank you. Mar 19 at 3:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.