本文整理汇总了Python中discord.Channel方法的典型用法代码示例。如果您正苦于以下问题:Python discord.Channel方法的具体用法?Python discord.Channel怎么用?Python discord.Channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.Channel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def _add(self, ctx, account, channel:discord.Channel=None):
"""Adds a twitter account to the specified channel"""
api = await self.authenticate()
try:
for status in tw.Cursor(api.user_timeline, id=account).items(1):
user_id = str(status.user.id)
screen_name = status.user.screen_name
last_id = status.id
except tw.TweepError as e:
print("Whoops! Something went wrong here. \
The error code is " + str(e) + account)
await self.bot.say("That account does not exist! Try again")
return
if channel is None:
channel = ctx.message.channel
added = await self.add_account(channel, user_id, screen_name)
if added:
await self.bot.say("{0} Added to {1}!".format(account, channel.mention))
else:
await self.bot.say("{} is already posting or could not be added to {}".format(account, channel.mention))
示例2: channel
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def channel(self, ctx, channel : discord.Channel=None):
"""Sets the channel to send the welcome message
If channel isn't specified, the server's default channel will be used"""
server = ctx.message.server
if channel is None:
channel = ctx.message.server.default_channel
if not server.get_member(self.bot.user.id
).permissions_in(channel).send_messages:
await self.bot.say("I do not have permissions to send "
"messages to {0.mention}".format(channel))
return
self.settings[server.id]["CHANNEL"] = channel.id
dataIO.save_json(settings_path, self.settings)
channel = self.get_welcome_channel(server)
await self.bot.send_message(channel, "I will now send welcome "
"messages to {0.mention}".format(channel))
await self.send_testing_msg(ctx)
示例3: run_test
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def run_test(self,
test: Test,
channel: discord.Channel,
stop_error: bool = False) -> TestResult:
''' Run a single test in a given channel.
Updates the test with the result, and also returns it.
'''
interface = Interface(
self,
channel,
self._find_target(channel.server))
try:
await test.func(interface)
except TestRequirementFailure:
test.result = TestResult.FAILED
if not stop_error:
raise
else:
test.result = TestResult.SUCCESS
return test.result
示例4: _display_stats
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def _display_stats(self, channel: discord.Channel) -> None:
''' Display the status of the various tests. '''
# NOTE: An emoji is the width of two spaces
response = '```\n'
longest_name = max(map(lambda t: len(t.name), self._tests))
for test in self._tests:
response += test.name.rjust(longest_name) + ' '
if test.needs_human:
response += '✋ '
else:
response += ' '
if test.result is TestResult.UNRUN:
response += '⚫ Not run\n'
elif test.result is TestResult.SUCCESS:
response += '✔️ Passed\n'
elif test.result is TestResult.FAILED:
response += '❌ Failed\n'
response += '```\n'
await self.send_message(channel, response)
示例5: setup_starboard
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def setup_starboard(self, ctx, channel: discord.Channel=None, emoji="⭐", role:discord.Role=None):
"""Sets the starboard channel, emoji and role"""
server = ctx.message.server
if channel is None:
channel = ctx.message.channel
if "<" in emoji and ">" in emoji:
emoji = await self.check_server_emojis(server, emoji)
if emoji is None:
await self.bot.send_message(ctx.message.channel, "That emoji is not on this server!")
return
else:
emoji = ":" + emoji.name + ":" + emoji.id
if role is None:
role = await self.get_everyone_role(server)
self.settings[server.id] = {"emoji": emoji,
"channel": channel.id,
"role": [role.id],
"threshold": 0,
"messages": [],
"ignore": []}
dataIO.save_json("data/star/settings.json", self.settings)
await self.bot.say("Starboard set to {}".format(channel.mention))
示例6: _del
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def _del(self, ctx, account, channel:discord.Channel=None):
"""Removes a twitter account to the specified channel"""
account = account.lower()
api = await self.authenticate()
if channel is None:
channel = ctx.message.channel
try:
for status in tw.Cursor(api.user_timeline, id=account).items(1):
user_id = str(status.user.id)
except tw.TweepError as e:
print("Whoops! Something went wrong here. \
The error code is " + str(e) + account)
await self.bot.say("That account does not exist! Try again")
return
removed = await self.del_account(channel, user_id)
if removed:
await self.bot.say("{} has been removed from {}".format(account, channel.mention))
else:
await self.bot.say("{0} doesn't seem to be posting in {1}!"
.format(account, channel.mention))
示例7: add_goals
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def add_goals(self, ctx, team, channel:discord.Channel=None):
"""Adds a hockey team goal updates to a channel"""
if team.lower() == "all":
team = "all"
else:
try:
team = [team_name for team_name in self.teams if team.lower() in team_name.lower()][0]
except IndexError:
await self.bot.say("{} is not an available team!".format(team))
return
if channel is None:
channel = ctx.message.channel
if team not in self.settings:
self.settings[team] = {"channel":[channel.id], "goal_id": {}}
if channel.id in self.settings[team]["channel"]:
await self.bot.send_message(ctx.message.channel, "I am already posting {} goals in {}!".format(team, channel.mention))
return
self.settings[team]["channel"].append(channel.id)
dataIO.save_json("data/hockey/settings.json", self.settings)
await self.bot.say("{} goals will be posted in {}".format(team, channel.mention))
示例8: remove_goals
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def remove_goals(self, ctx, team, channel:discord.Channel=None):
"""Removes a teams goal updates from a channel"""
if team.lower() == "all":
team = "all"
else:
try:
team = [team_name for team_name in self.teams if team.lower() in team_name.lower()][0]
except IndexError:
await self.bot.say("{} is not an available team!".format(team))
return
if channel is None:
channel = ctx.message.channel
if team not in self.settings:
await self.bot.send_message(ctx.message.channel, "I am not posting {} goals in {}".format(team, channel.mention))
return
if channel.id in self.settings[team]["channel"]:
self.settings[team]["channel"].remove(channel.id)
dataIO.save_json("data/hockey/settings.json", self.settings)
await self.bot.say("{} goals will stop being posted in {}".format(team, channel.mention))
示例9: add_server
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def add_server(self, ctx, channel:discord.Channel=None, role:discord.Role=None, invite_link=None):
"""Set the server for activity checking"""
server = ctx.message.server
if channel is None:
channel = ctx.message.channel
if role is not None:
role = role.id
if role is None:
role = await self.get_everyone_role(server)
if server.id in self.log:
await self.bot.say("This server is already checking for activity!")
return
if invite_link is None:
await self.bot.say("You'll need to supply an invite link if you want one for members to rejoin")
self.settings[server.id] = {"channel": channel.id,
"check_roles": [role],
"time": 604800,
"invite": True,
"link": invite_link,
"rip_count": 0}
dataIO.save_json(self.settings_file, self.settings)
await self.build_list(ctx, server)
await self.bot.send_message(ctx.message.channel, "Sending activity check messages to {}".format(channel.mention))
示例10: set_channel
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def set_channel(self, ctx, on_off: bool, channel: discord.Channel = None):
"""
Sets channel logging on or off (channel optional)
To enable or disable all channels at once, use `logset server`.
"""
if channel is None:
channel = ctx.message.channel
server = channel.server
if server.id not in self.settings:
self.settings[server.id] = {}
self.settings[server.id][channel.id] = on_off
if on_off:
await self.bot.say('Logging enabled for %s' % channel.mention)
else:
await self.bot.say('Logging disabled for %s' % channel.mention)
self.save_json()
示例11: format_overwrite
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def format_overwrite(target, channel, before, after):
target_str = 'Channel overwrites: {0.name} ({0.id}): '.format(channel)
target_str += 'role' if isinstance(target, discord.Role) else 'member'
target_str += ' {0.name} ({0.id})'.format(target)
if before:
bpair = [x.value for x in before.pair()]
if after:
apair = [x.value for x in after.pair()]
if before and after:
fmt = ' updated to values %i, %i (was %i, %i)'
return target_str + fmt % tuple(apair + bpair)
elif after:
return target_str + ' added with values %i, %i' % tuple(apair)
elif before:
return target_str + ' removed (was %i, %i)' % tuple(bpair)
示例12: embedwiz_channel
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def embedwiz_channel(self, ctx, channel: discord.Channel, *, specification):
"""
Posts an embed in another channel according to the spec.
See [p]help embedwiz for more information.
"""
member = channel.server and channel.server.get_member(ctx.message.author.id)
override = self._check_override(member)
if channel != ctx.message.channel and not member:
await self.bot.say(error("Channel is private or you aren't in the server that channel belongs to."))
return
elif not channel.permissions_for(member).send_messages:
msg = error("You don't have permissions to post there!")
await self.bot.say(msg)
return
embed = await self._parse_embed(ctx, specification, force_author=not override)
if embed:
await self.bot.send_message(channel, embed=embed)
if channel != ctx.message.channel:
await self.bot.say("Embed sent to %s." % channel.mention)
示例13: cleanup_task
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def cleanup_task(self, channel: discord.Channel) -> None:
try:
to_delete = []
settings = self.settings_for(channel)
now = datetime.utcnow()
before = now - timedelta(seconds=settings["EXPIRATION"])
after = now - timedelta(days=14, seconds=-30)
check = self.get_message_check(channel, settings=settings)
while True:
async for message in self.bot.logs_from(channel, before=before, after=after):
before = message
if await check(message):
to_delete.append(message)
else:
break
while to_delete and to_delete[-1].timestamp < after:
to_delete.pop()
if to_delete:
await self.mass_purge(to_delete)
except Exception as e:
raise CleanupError(channel, e)
示例14: quote_add_msg
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def quote_add_msg(self, ctx, message_id: int, channel: discord.Channel = None):
"""
Adds a message to the server quote database
The full text of the message is used. If the message belongs to
another channel, specify it as the second argument.
"""
try:
msg = await self.bot.get_message(channel or ctx.message.channel, str(message_id))
except discord.errors.NotFound:
await self.bot.say(warning("Couldn't find that message in %s."
% (channel.mention if channel else 'this channel')))
return
if msg.content or msg.attachments or (msg.embeds and msg.embeds[0].get('type') == 'image'):
self._update_member(ctx.message.author)
self._update_member(msg.author)
ret = self._add_quote(ctx, message=msg)
await self.bot.say(okay("Quote #%i added." % ret['server_quote_id']))
else:
await self.bot.say(warning("Cannot add a quote with no text, attachments or embed images."))
示例15: gquote_add_msg
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Channel [as 别名]
def gquote_add_msg(self, ctx, message_id: int, channel: discord.Channel = None):
"""
Adds a message to the server global quote database
The full text of the message is used. If the message belongs to
another channel, specify it as the second argument.
"""
try:
msg = await self.bot.get_message(channel or ctx.message.channel, str(message_id))
except discord.errors.NotFound:
await self.bot.say(warning("Couldn't find that message in %s."
% (channel.mention if channel else 'this channel')))
return
if msg.content or msg.attachments or (msg.embeds and msg.embeds[0].get('type') == 'image'):
self._update_member(ctx.message.author)
self._update_member(msg.author)
ret = self._add_quote(ctx, message=msg, is_global=True, server=False)
await self.bot.say(okay("Global quote #g%i added." % ret['quote_id']))
else:
await self.bot.say(warning("Cannot add a quote with no text, attachments or embed images."))