Reputation: 113
import os
from discord.ext import commands
bot = commands.Bot(command_prefix='~')
for fileName in os.listdir('cogs'):
if fileName.endswith('.py') and fileName != '__init__.py':
bot.load_extension(f'cogs.{fileName[:-3]}')
bot.run(* TOKEN * )
The problem is on the code below:
import discord
from discord.ext import commands
class MoveMembers(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.channel_to_move= discord.Client().get_channel(* channel ID *)
@commands.command()
async def send_to_channel(self, ctx, *members: discord.Member):
for member in members:
if member.voice:
print(type(self.channel_to_move))
await member.move_to(self.channel_to_move)
await ctx.send('message recieved')
def setup(bot):
bot.add_cog(MoveMembers(bot))
The point of this function is to move one or more memebers that have been referenced to a specefic voice chanel.
example: "~send_to_channel @person"
The function is called but for some reason "discord.Client().get_channel(* channel ID *)" doesn't return a voice channel, or any channel at that. I've read the documentation and some other answers in stack overflow but I can't figure out what is wrong...
**** EDIT **** Also does anyone know why this code doesn't work:
def move_rights():
def predicate(ctx):
return commands.check_any(commands.is_owner(),
commands.has_role("Move Rights"))
return commands.check(predicate)
@commands.command()
@move_rights()
async def send_to_gulag(self, ctx, *members: discord.Member):
for member in members:
if member.voice:
await member.move_to(self.gulag)
await ctx.send('message recieved')
Everyone can use this command so I don't know if the "move_rights()" functions returns always "true" or if just didn't implement it right. (The code is part of the code in the original question)
Upvotes: 0
Views: 529
Reputation: 15689
In self.channel_to_move= discord.Client().get_channel(* channel ID *)
you're not supposed to refer to the class itself, but to the instance
self.channel_to_move = self.bot.get_channel(* channel ID *)
It's important to know the difference between classes and instances
Upvotes: 2