Move user to a textchannel as soon as he has pressed a button

2024/11/18 18:46:32

I have a problem. I would like to move a user from one specific textchannel to another specific textchannel as soon as he has pressed a button. Unfortunately I get an error.

class MyView(discord.ui.View): # Create a class called MyView that subclasses discord.ui.View@discord.ui.button(label="->", style=discord.ButtonStyle.primary, emoji="😎") async def button_callback(self, button, interaction):channel = interaction.guild.get_channel(os.getenv('CHANNEL_ID_SETUP2'))await discord.Member.move_to(channel)@commands.has_permissions(administrator=True, ban_members=True) 
@bot.command()
async def button(ctx):await ctx.send(view=MyView())
TypeError: move_to() missing 1 required positional argument: 'channel'
Answer

You're getting that error because you're calling move_to on the class name, not an instance. Discord.py has no idea which member you want to move when you write discord.Member.move_to(), you need an instance of the class.

You mentioned wanting to move the person when they click on the button, so you can get their Member instance using interaction.user.

As for making a member see a message, that isn't like "moving". That's what happens when you click on a message's jump_url.

https://en.xdnf.cn/q/120042.html

Related Q&A

scrape the about page of websites with Python [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Tkinter entry widget execution [duplicate]

This question already exists:Entry widget in tkinterClosed 2 years ago.So I made a simple program however it doesnt seem to work my code is: e = Entry(root, font = 20,borderwidth=5)e.grid(row=1)def cap…

Python Redefine the variable given as a parameter to the function

Hello I am trying to make theme window with tkinter. There is 5 variable for different widgetss color. I will use color dialog for choosing colors but I dont want to define 5 functions. So I think I ca…

Need a Gui Keypad for a touchscreen that outputs a pin when code is correct

I have a raspberry pi with a touchscreen running raspbian, Im hoping to have a Gui on the touchscreen that had a number keypad that when a correct input is entered a pin will output to a door latch or …

How can i make the python to wait till i complete speaking?

I am writing a program to recognise the speech from a microphone and the code will process accordingly. The code I wrote for this purpose is below.import speech_recognition as sr import webbrowser impo…

Facing AttributeError: list object has no attribute lower

I have posted my sample train data as well as test data along with my code. Im trying to use Naive Bayes algorithm to train the model.But, in the reviews Im getting list of list. So, I think my code is…

why I cannot use max() function in this case? [duplicate]

This question already has answers here:Why do I get "TypeError: int object is not iterable" when trying to sum digits of a number? [duplicate](4 answers)Closed 1 year ago.n,m,k=map(int, inpu…

SQLALchemy and Python - Getting the SQL result

I am using cloudkitty which is rating module in OpenStacks.But here question is regarding the SQLAlchemy and Python.I am new to SQLAlchemy.I need to fetch some details from a table using a API call.So …

ValueError: invalid literal for int() with base 10: python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Closed 10 years ago.Questions asking for code must demonstrate a minimal understanding of the proble…

python code to connect to sftp server

I found this code to connect to remote sftp server with the help of username ,password and host but i also need to include the port number, can any one let em know how to include the port number in thi…